文章摘要
这篇文章讨论了在Vue动态路由中传递组件时遇到的报错问题。具体来说,动态路由组件在传递变量时,可能会报错,导致页面空白。解决方法包括:
1. 使用`Vue Router`来简化动态路由的配置和实现。
2. 在动态路由中使用`@/`路径,可以在组件中明确指定组件的名称,避免依赖注入的问题。
3. 在组件中使用`Vue Router`的方法,确保依赖注入的正确性。
这篇文章还提到了其他相关文章,供读者进一步了解动态路由的实现和解决方法。
目录menuList 后台数据返回格式路由里面component
{
// 统计分析
path: ‘/statistics’,
name: ‘Statistics’,
meta:{title: ‘数据统计’},
component: ‘views/statistics/Statistics’
}
// 统计分析
path: ‘/statistics’,
name: ‘Statistics’,
meta:{title: ‘数据统计’},
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}`))
// 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 动态路由传递变量报错的资料请关注脚本之家其它相关文章!
您可能感兴趣的文章:vue-router4动态路由刷新404/白屏的解决Vue router动态路由实现过程Vue实现动态路由导航的示例vue实现动态路由添加功能的简单方法(无废话版本)Vue动态路由路径重复及刷新丢失页面问题的解决Vue中如何实现动态路由的示例代码
© 版权声明
文章版权归作者所有,未经允许请勿转载。