gpt4 book ai didi

javascript - 未捕获的 TypeError : Cannot set property 'app' of undefined Vue. js

转载 作者:行者123 更新时间:2023-12-03 11:17:18 24 4
gpt4 key购买 nike

我想使用 Laravel 5.4 和 Vue2 设置一个 SPA。我有一个教程(Jeffrey Way - Laracast)。但我遇到了这个问题。无法弄清楚为什么控制台中出现此错误? :

Uncaught TypeError: Cannot set property 'app' of undefined
at VueRouter (app.js:3149)
at Object.<anonymous> (app.js:4266)
at __webpack_require__ (app.js:20)
at Object.<anonymous> (app.js:3343)
at __webpack_require__ (app.js:20)
at Object.<anonymous> (app.js:13749)
at __webpack_require__ (app.js:20)
at app.js:66
at app.js:69


下面是我的代码:

应用程序.js
import router from './routes';

import './bootstrap';

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

路由.js
import VueRouter from 'vue-router';

let routes = [
{
path: '/',
component: require('./views/Home')
}
];

export default VueRouter({
routes
});

Bootstrap .js
import Vue from 'vue';
import VueRouter from 'vue-router';
import axios from 'axios';

window.Vue = Vue;
window.axios = axios;
Vue.use(VueRouter);

window.axios.defaults.headers.common = {
'X-CSRF-TOKEN': window.Laravel.csrfToken,
'X-Requested-With': 'XMLHttpRequest'
};

最佳答案

export default new VueRouter({
routes
});

添新”

关于javascript - 未捕获的 TypeError : Cannot set property 'app' of undefined Vue. js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43430000/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com