vue 动态路由用代码怎么写
Vue动态路由可以通过以下代码实现:
- 在路由配置文件中添加动态路由规则,例如:
{
path: '/user/:id',
name: 'user',
component: User
}
- 在组件中获取动态路由参数,例如:
export default {
name: 'User',
mounted () {
const id = this.$route.params.id
// 使用获取到的id进行其他操作
}
}
- 在代码中使用
router.push方法动态跳转到对应的路由,例如:
router.push({ name: 'user', params: { id: 123 }})
以上代码中,params属性用来传递动态路由参数。
原文地址: https://www.cveoy.top/t/topic/bPFU 著作权归作者所有。请勿转载和采集!