首页 > 解决方案 > 未捕获的 ReferenceError:Laravel 8 中未定义路由

问题描述

require('./bootstrap');
require('./ziggy');
window.Vue = require('vue');
const files = require.context('./', true, /\.vue$/i);
files.keys().map(key => {
    return Vue.component(_.last(key.split('/')).split('.')[0], files(key))
});
const app = new Vue({
    el: '#app',
})
Vue.mixin({
    methods: {
        route: route
    }
});

安装 Laravel 8 身份验证后,我在控制台中收到此错误。

app.js:63273 Uncaught ReferenceError: route is not defined at Module../resources/js/app.js (app.js:63273) at webpack_require (app.js:20) at Object.0 (app.js:63334 ) 在 webpack_require (app.js:20) 在 app.js:84 在 app.js:87 app.js:58049

下载 Vue Devtools 扩展以获得更好的开发。因此,我的 JavaScript 无法正常工作。我必须点击 auth 模块的 URL。

标签: javascriptvue.jslaravel-8

解决方案


之所以会发生这种情况,是因为这段代码。你没有声明route变量。因此,它会引发错误。

Vue.mixin({
methods: {
    route: route
}
});

推荐阅读