文章详情页
javascript - 动态添加路由报错
浏览:98日期: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. android - 启动模拟器的,报“Could not automatically detect an ADB binary……”,要怎么解决?2. 如何分别在Windows下用Winform项模板+C#,在MacOSX下用Cocos Application项目模板+Objective-C实现一个制作游戏的空的黑窗口?3. python - TypeError: tryMsgcode() takes exactly 2 arguments (0 given)4. javascript - 关于json中获取多个key-value对中多层嵌套key的name5. 关于docker下的nginx压力测试6. docker安装后出现Cannot connect to the Docker daemon.7. android clickablespan获取选中内容8. javascript - 最终生成的jsBundle文件压缩问题9. angular.js - angularjs的自定义过滤器如何给文字加颜色?10. node.js - 如何在服务器部署vuejs项目?
排行榜
