gpt4 book ai didi

javascript - Vue 路由器对象为 null

转载 作者:行者123 更新时间:2023-12-02 14:24:06 25 4
gpt4 key购买 nike

我在使用 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();
});
},

.....

但由于某种原因,我的路由器对象null。我收到错误:无法读取未定义的属性“go”(...)

我正在从 main.js 导入路由器

我在哪里制作这样的路由器:

var router = new Router({
history: true
});

请告诉我我在这里做错了什么!

最佳答案

我有这个:

var router = new Router({
history: true
});

而不是这个:

export var router = new Router({
history: true
});

@Ismail RBOUH 感谢您的帮助。

关于javascript - Vue 路由器对象为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38421797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com