Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught TypeError: Cannot set property 'app' of undefined Vue.js

I wanted to setup a SPA using Laravel 5.4 and Vue2. I have following a tutorial (Jeffrey Way - Laracast). But i am getting this issue. Can not figure it out why this error in console?? :

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

Here is my code below :

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'
};
like image 958
WahidSherief Avatar asked Sep 01 '25 22:09

WahidSherief


1 Answers

export default new VueRouter({
  routes
});

add "new"

like image 124
Shuai Shen Avatar answered Sep 03 '25 10:09

Shuai Shen