Search code examples
javascriptlaravelvue.jslaravel-5.3

Get vue.js 2.0 to work with Laravel 5.3


I'm trying to setup Vue.js 2.0 with Laravel 5.3. I would like to put the <router-view> </router-view> within a main App.vue component. How do I get this to work with Vue 2.0.

This is not working anymore:

router.start(App, 'app');

So I tried this:

const app = new Vue({
    router,
    render: h => h(App)
});

But that's not working for me. Do I've to pull in a package to get this to work?

Thanks!


Solution

  • You forgot to give a element where Vue code would be rendered.

    So, you have to declare root level with unique ID, for e.g #app and mount it to Vue instance.

    const app = new Vue({
        router,
        render: (h) => h(App)
    }).$mount('#app')
    

    You can go with spread operator, instead of render function, pretty same thing, maybe a bit cleaner to read

    const app = new Vue({
        router,
        ...App 
    }).$mount('#app')