【发布时间】:2016-07-17 13:33:52
【问题描述】:
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)
.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();
});
},
.....
但由于某种原因,我的router object 是null。我收到错误:Cannot read property 'go' of undefined(…)
我正在从 main.js 导入路由器
我在哪里制作这样的路由器:
var router = new Router({
history: true
});
请告诉我我在这里做错了什么!
【问题讨论】:
-
你需要在 main.js 中导出你的路由器!
-
@IsmailRBOUH 谢谢你的作品:)
-
请添加一个答案并将其标记为已接受(这样以后遇到相同问题的人将能够轻松发现它)。
标签: javascript browserify vue.js