vue动态路由component传递变量报错的解决方法

2024-03-14,,

本篇文章和大家了解一下vue动态路由component传递变量报错的解决方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

menuList 后台数据返回格式

{
    // 统计分析
    path: '/statistics',
    name: 'Statistics',
    meta:{title: '数据统计'},
    component: 'views/statistics/Statistics'
}

路由里面component

接收的是 @/views/statistics/Statistics 能正常显示页面

如果动态参数,以下三种都会报错,页面空白

let cop = `@/${item.component}`
// item.component = () => import(cop)
// item.component = resolve => require([cop], resolve)
// item.component = Promise.resolve().then(() => require(`@/${item.component}`))

请问有没有好的办法解决这个问题?

name为组件页面地址

item.component = (name) => () => import(`@/${name}.vue`)

以上就是vue动态路由component传递变量报错的解决方法的简略介绍,当然详细使用上面的不同还得要大家自己使用过才领会。如果想了解更多,欢迎关注本站行业资讯频道哦!

《vue动态路由component传递变量报错的解决方法.doc》

下载本文的Word格式文档,以方便收藏与打印。