Programing

부에루터:TypeError: 이것._불쌍한init는 함수가 아님

c10106 2022. 3. 24. 21:25
반응형

부에루터:TypeError: 이것._불쌍한init는 함수가 아님

Laravel 프로젝트 내에 Vue-router를 설치한 후 다음을 사용해 보십시오.

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

그리고 난 이걸 이해한다:

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

흥미롭게도, 이전에는 모든 것이 괜찮았지만, 갑자기 이 메시지를 받기 시작했다.

대체하다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) 
});

내 app.js는 다음과 같이 보인다.

require('./bootstrap');

window.Vue = require('vue');

import VueRouter from 'vue-router'

Vue.use(VueRouter)

/**
 * 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.
 */

Vue.component('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 = ({
    mode: 'history',
    routes
})

const app = new Vue({
    el: '#app',
    router
});

참조URL: https://stackoverflow.com/questions/51462715/vue-router-typeerror-this-router-init-is-not-a-function

반응형