0
我遇到了vue问题。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谢谢:) – Jamie
请添加一个答案并将其标记为已接受(以便将来人们面对同样的问题将能够轻松发现)。 –