I have been trying to setup a simple vue application using VueRouter with Laravel. But the vue-router is not loading the components properly.
welcome.blade.php
<body>
<div id="app">
<main-app/>
</div>
<script src="{{ asset('js/app.js') }}"></script>
</body>
app.js
//import Vue from 'vue';
window.Vue = require('vue');
import VueRouter from 'vue-router';
import {
routes
} from './routes';
import MainApp from './components/MainApp.vue';
Vue.use(VueRouter);
const router = new VueRouter({
routes,
mode: 'history'
});
const app = new Vue({
el: '#app',
router,
components: {
MainApp
}
});
routes.js
import Home from './components/Home.vue'
export const routes = [{
path: '/',
component: Home,
name: 'Home'
}];
MainApp.vue
<template>
<div id="main">
<router-view></router-view>
</div>
</template>
If http://localhost:8080/vue-spa
is dialed, "Home component" should be displayed (which we are displaying in Home.vue). But , nothing is displaying.
I am new to Vue , help to find a solution for this.
window.Vue = require('vue')
, please dowindow.Vue = Vue
; Let me know if that changes anything – Matthias Swindow.Vue = require('vue')
on top and remove theimport Vue from ' vue'
part. I am not sure if it changes things but I don't like importing vue twice in the same file through different methods. Can you go toMainApp.vue
and add this to thecreated
hook:console.log(this.$router, this.$route)
– Matthias S