2017-08-31 51 views
0

以我的第一次刺Vue2和卡住路线。Vue2:试图使用时的视图路由器异常<router-view>

基本上,当我加入<router-view></router-view>到index.html的我开始收到异常:

[Vue warn]: Failed to mount component: template or render function not 
defined. 

found in 

---> <Anonymous> 
     <Root> 

的GitHub代码链接:https://github.com/kernelcurry/httpverbs-site/tree/c56ba0a45445f7d28c31cb6928471da3619a3327

我连抬头的视频教程关于这个主题,他们似乎没有问题,但我确实。 (视频链接:https://laracasts.com/series/learn-vue-2-step-by-step/episodes/26

为了澄清,并没有出现错误,直到我说<router-view></router-view>index.html(线路链接:https://github.com/kernelcurry/httpverbs-site/blob/c56ba0a45445f7d28c31cb6928471da3619a3327/index.html#L10

我希望我可以给更多的洞察是怎么回事,但我我不知所措。由于任何人愿意看的代码,并指出我在正确的方向:)

回答

1

更改src/routes.js如下:

import VueRouter from 'vue-router'; 
 
import Home from './views/home.vue' 
 
import About from './views/about.vue' 
 

 
let routes = [ 
 
    { 
 
     path: '/', 
 
     component: Home 
 
    }, 
 
    { 
 
     path: '/about', 
 
     component: About 
 
    } 
 
]; 
 

 
export default new VueRouter({ 
 
    routes 
 
});

+0

工作!但为什么?!为什么必须将'* .vue'文件导入到文件的顶部而不是内联? – michaelcurry

+0

因为您的vue文件需要使用webpack vue-loader转换为普通的javascript模块,所以这会在您的构建过程中遇到导入时执行。 –