未捕获的类型错误:无法设置未定义的 Vue.js 的属性“app”
2017-04-15
7223
我想使用 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
以下是我的代码:
app.js
import router from './routes';
import './bootstrap';
var app = new Vue({
el: '#root',
router
});
routes.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'
};
2个回答
export default new VueRouter({
routes
});
添加“新”
Shuai Shen
2017-04-22
let routes = [
{
path: '/',
component: require('./views/Home')
}
];
export default new VueRouter({
routes
});
Rajim
2019-08-27