2017-08-31 50 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模塊,所以這會在您的構建過程中遇到導入時執行。 –