当我使用浏览器字段输入URL时,参数将转换为字符串,而不是整数,例如/user/1return {id: "1"}。但是,当使用时this.$route.push({}),参数正确地转换为integer {id: 1}。
这是故意行为吗?如果没有,我该如何解决?
Nic*_*all 11
您必须自己处理任何参数值。在路线对象中定义道具功能。这是一个例子:
{
path: '/user/:userId',
component: UserProfile,
props: (route) => {
const userId = Number.parseInt(route.params.userId, 10)
if (Number.isNaN(userId)) {
return 0
}
return { userId }
}
}
Run Code Online (Sandbox Code Playgroud)
链接到vue路由器文档,这在功能模式下
| 归档时间: |
|
| 查看次数: |
3737 次 |
| 最近记录: |