【报错】route config “component“ for path: /test cannot be a string id. Use an actual component instead.

淩亂°似流年 2023-01-16 02:50 185阅读 0赞

vue-router配置组件:config component
这个是错误代码

  1. const routes = [
  2. {
  3. path: '/test',
  4. name: '路由测试',
  5. component: './view/test'
  6. }
  7. ]

cannot be a string id,Use an actual component instead 不能是一个字符串id,用一个实际的组件代替。

解决方法:不能直接在 component使用字符串显示路径,需要设置别名。
正确代码

  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. //自定义页面
  4. import Test from './view/test'
  5. //安装路由到vue
  6. Vue.use(Router)
  7. const routes = [
  8. {
  9. path: '/test',
  10. name: '路由测试',
  11. component: Test
  12. }
  13. ]
  14. export default new Router({
  15. routes
  16. })

发表评论

表情:
评论列表 (有 0 条评论,185人围观)

还没有评论,来说两句吧...

相关阅读