无法使用view-router解析异步组件呈现

时间:2017-06-17 09:05:21

标签: javascript vue.js vue-component vue-router

我尝试用VueRouter实现VueJs。 Home组件显示日志消息,但不显示模板部分。我得到以下错误:

enter image description here

Home.vue

<template>
    <div class="wrap" id="app">
        <h1 class="inline">Hello There</h1>
    </div>
</template>

<script>
export default {
    name: 'app',
    data () {
        return {
            maps: []
        }
    },
    mounted() {
        console.log( 'Mounted Homepage' );
    }
}
</script>

<style lang="scss">
#app {
   font-family: 'Avenir', Helvetica, Arial, sans-serif;
   -webkit-font-smoothing: antialiased;
   -moz-osx-font-smoothing: grayscale;
}
</style>

routes.js

import Vue from 'vue';
import Home from './components/Home.vue';
import NotFound from './components/NotFound.vue';

const routes = [
    { name: 'home', path: '/', components: Home },
    { path: '*', component: NotFound, meta: { title: 'Not Found' } }
];

import VueRouter from 'vue-router';
Vue.use(VueRouter);


var router = new VueRouter({
    routes
})

export default router;

Main.js

import Vue from 'vue'
import NotFound from './components/NotFound.vue'
import router from './routes'

new Vue({
    router,
    components: {
        NotFound
    }
}).$mount('#rgm_app');

你能告诉我我错过了什么吗?

1 个答案:

答案 0 :(得分:14)

你在这个数组声明中有一个拼写错误:

const routes = [
    { name: 'home', path: '/', components: Home },
    { path: '*', component: NotFound, meta: { title: 'Not Found' } }
];

只需从第一个对象上的组件中删除额外的 s ,就可以了。