Vue JS with a vue router not loading vueified components

I am developing a web application that uses vue-router for SPA with the Laravel 5 backend. It uses files .vuefor application components that are run through laravel-elixir-vueifyto create the necessary JavaScript.

I installed vue-router with Vue successfully and can load the components defined in the same file as the main Vue and Vue router instances.

The problem occurs when I try and require the component that is contained in the file .vue. Although the browser / vueify reports a successful launch when I check the Vue instance, it only has anonymous component snippets shown in the instance by Vue dev tools, and no markup placed inside router-view.

Vue devtools

There are no errors in the console, although it seems that external components do not load correctly.

Examples of various codes and files are as follows:

gulpfile.js

...
    mix.browserify('dashboard.js');
...

dashboardOverview.vue

<template>
    <div>
        <h1>Overview</h1>
        <img src="//placehold.it/320x100" style="width: 100%; margin-bottom: 15px" alt="Pathway Visualisation" />
    </div>
</template>

<script>

    export default {}

</script>

Where dashboardOverview.vueis at resources\assets\js\components\dashboardOverview.vue.

Main view

@section('content')
<div id="app">
    <h1>Welcome</h1>
    <a v-link="{ path: '/activate' }">Activate</a>|
    <a v-link="{ path: '/' }">Overview</a>
    <router-view></router-view>
</div>
@endsection

This is complemented by the following JavaScript:

var Vue = require('vue');
var VueRouter = require('vue-router');

Vue.use(VueRouter)

/* Components */
var dashboardOverview = require('./components/dashboardOverview.vue');
var userSetup = require('./components/userSetup.vue');

var App = Vue.extend();

var router = new VueRouter()
Vue.config.debug = true

router.map({
    '*': {
        component: Vue.extend({template: '<h4>404 Not found</h4>'})
    },
    '/': {
        component: dashboardOverview
    },
    '/activate': {
        component: userSetup
    }
})

router.start(App, '#app')

Where dashboard.jsis at resources\assets\js\dashboard.js.

+4
source share
1 answer

I set up a minimal test project and was able to successfully achieve what I was aiming for.

The end result was several Node packages that had incompatible versions, as well as packages that were not required.

packages.json, vue, vue-router laravel-elixir-vueify, , , .

+3

All Articles