Javascript Vue路由器对象为空
我对vue有问题 我的登录名如下所示:Javascript Vue路由器对象为空,javascript,browserify,vue.js,Javascript,Browserify,Vue.js,我对vue有问题 我的登录名如下所示: import Vue from 'vue'; import {router} from '../main'; export default { user: { authenticated: false, id: 0, name: '', email: '' }, login (context, creds) { Vue.http.post('/api/login', creds) .th
import Vue from 'vue';
import {router} from '../main';
export default {
user: {
authenticated: false,
id: 0,
name: '',
email: ''
},
login (context, creds) {
Vue.http.post('/api/login', creds)
.then(({data: {token}}) => {
// Hide the error message in case this time
// the creds were valid.
context.hideError();
this.setToken(token);
this.getUserInfo(token);
router.go({ path: '/home' });
}, (error) => {
// Show some error message on the invoking vm
// telling the user that his/her credentials
// are wrong.
context.showError();
});
},
.....
var router = new Router({
history: true
});
但由于某种原因,我的路由器对象
为空
。我收到错误:无法读取未定义(…)的属性“go”
我正在从main.js导入路由器
我制作路由器的地方如下:
import Vue from 'vue';
import {router} from '../main';
export default {
user: {
authenticated: false,
id: 0,
name: '',
email: ''
},
login (context, creds) {
Vue.http.post('/api/login', creds)
.then(({data: {token}}) => {
// Hide the error message in case this time
// the creds were valid.
context.hideError();
this.setToken(token);
this.getUserInfo(token);
router.go({ path: '/home' });
}, (error) => {
// Show some error message on the invoking vm
// telling the user that his/her credentials
// are wrong.
context.showError();
});
},
.....
var router = new Router({
history: true
});
请告诉我我做错了什么 我有这个:
var router = new Router({
history: true
});
与此相反:
export var router = new Router({
history: true
});
@伊斯梅尔:谢谢你的帮助。我有这个:
var router = new Router({
history: true
});
与此相反:
export var router = new Router({
history: true
});
@Ismail RBOUH感谢您的帮助。您需要在main.js中导出路由器@IsmailRBOUH感谢您的帮助:)请添加一个答案并将其标记为已接受(这样将来面临相同问题的人将能够轻松发现)。您需要在main.js中导出路由器@IsmailRBOUH:谢谢你这么做:)请添加一个答案,并将其标记为已接受(这样将来面对相同问题的人将能够很容易地发现它)。