Vue-Router:TypeError:this._router.init不是函数

时间:2018-07-22 06:51:23

标签: vuejs2 vue-router

我已经安装了vue-router(在Laravel项目中),然后尝试使用它:

import VueRouter from 'vue-router'
Vue.use(VueRouter)

然后我得到了:

[Vue warn]: Error in beforeCreate hook: "TypeError: this._router.init is not a function"

有趣的是,以前一切都很好,但是突然开始收到此消息。

2 个答案:

答案 0 :(得分:1)

在您的Webpack配置中将vue替换为vue-loader https://github.com/vuejs/vue-loader/issues/409

更新

好的,显然您没有以正确的方式初始化路由器

require('./bootstrap');
import Vue from 'vue'
import VueRouter from 'vue-router'


/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */

let home = require('./components/Home.vue'));
let buy = require('./components/Buy.vue');
let home = require('./components/Home.vue');
let sell = require('./components/Sell.vue');
let wallet = require('./components/Wallet.vue');


const routes = [{
        path: '/',
        component: home
    },
    {
        path: '/buy',
        component: buy
    },
    {
        path: '/sell',
        component: sell
    },
    {
        path: '/wallet',
        component: wallet
    }

];

const router = new VueRouter
({
    mode: 'history',
    routes
})

Vue.use(VueRouter);

window.app = new Vue({
    el: '#app',
    router,
    render: h => h(home) 
});

答案 1 :(得分:0)

这是我的app.js的样子:

asInstanceOf