Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Vue路由器对象为空_Javascript_Browserify_Vue.js - Fatal编程技术网

Javascript 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

我对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();
      });
  },

.....
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:谢谢你这么做:)请添加一个答案,并将其标记为已接受(这样将来面对相同问题的人将能够很容易地发现它)。