vue-router動態添加路由報錯


【報錯】

Uncaught Error: 
[vue-router] route config "component" for path: /home cannot be a string id.
Use an actual component instead

運行時不報錯,但是頁面顯示空白。打開控制台顯示下圖:

.

【報錯解析】

路徑/home的[vue router]route config“component”不能是字符串id 請改用實際的組件

在以下代碼中定位,可以看到是組件的錯誤component

export default new Router({
  routes: [
    {
      path:'/',
      redirect:'/home'
    },
    {
      path:'/home',
      component:'Home'
    },
    {
      path:'/cart',
      component:'Cart'
    },
    {
      path:'/profile',
      component:'Profile'
    }
  ]
})

發現  component:'Profile' 不能加引號

【解決方法】

去掉引號(component:Profile)后界面即可正常顯示。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM