文章詳情頁
javascript - 動態添加路由報錯
瀏覽:95日期: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
相關文章:
1. 前端 - node vue webpack項目文件結構2. 如何分別在Windows下用Winform項模板+C#,在MacOSX下用Cocos Application項目模板+Objective-C實現一個制作游戲的空的黑窗口?3. html5和Flash對抗是什么情況?4. php如何獲取訪問者路由器的mac地址5. javascript - 在 vue里面用import引入js文件,結果為undefined6. Java反射問題:為什么android.os.Message的recycleUnchecked方法不能通過反射獲取到?7. 小程序怎么加外鏈,語句怎么寫!求救新手,開文檔沒發現8. python - linux怎么在每天的凌晨2點執行一次這個log.py文件9. javascript - vue-resource中如何設置全局的timeout?10. thinkPHP5中獲取數據庫數據后默認選中下拉框的值,傳遞到后臺消失不見。有圖有代碼,希望有人幫忙
排行榜
