【问题标题】:Vue router object is nullVue 路由器对象为空
【发布时间】: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 objectnull。我收到错误:Cannot read property 'go' of undefined(…)

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

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

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

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

【问题讨论】:

  • 你需要在 main.js 中导出你的路由器!
  • @IsmailRBOUH 谢谢你的作品:)
  • 请添加一个答案并将其标记为已接受(这样以后遇到相同问题的人将能够轻松发现它)。

标签: javascript browserify vue.js


【解决方案1】:

我有这个:

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

而不是这个:

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

@Ismail RBOUH 感谢您的帮助。

【讨论】:

    猜你喜欢
    • 2019-12-02
    • 2019-12-07
    • 2018-02-10
    • 1970-01-01
    • 2021-02-08
    • 1970-01-01
    • 2019-10-24
    • 2018-11-03
    • 1970-01-01
    相关资源
    最近更新 更多