文章詳情頁
javascript - 動態添加路由報錯
瀏覽:73日期:2023-03-19 08:48:39
問題描述
動態添加了路由然后就報錯了,添加動態路由的代碼如下,data是后臺獲取的數據,自己寫了個404頁面,path: ’/404’也沒有這個錯誤。
data.permission = [{ path: ’/index’, name: ’index’, component: ’./../views/layout/index’}]this.$router.addRoutes(data.permission)
然后就報下面的錯誤,求解
Uncaught (in promise) Error: [vue-router] route config 'component' for path: /index cannot be a string id. Use an actual component instead.
問題解答
回答1:component字段加個require,錯誤信息理解錯了
component:require(’./../views/layout/index.vue’)回答2:
component需要一個組件實例,不能給路徑可以通過import或require引入
標簽:
JavaScript
相關文章:
排行榜
