gpt4 book ai didi

vue.js - 为什么 Vue3 路由器不传递带有参数的 Prop ?

转载 作者:行者123 更新时间:2023-12-05 05:08:34 24 4
gpt4 key购买 nike

我想在 Vue3 中将一个值作为 prop 传递给 View 。这种方法在 Vue2 项目中运行良好,但在 Vue3 中运行不佳

路由器:

{      
path: "/view2",
name: "view2",
component: View2,
props: true
}

查看 1(来自)

navigateTo(){
this.$router.push({
name: view2,
params: {id: 'abc123'}
})
}

查看 2(到)

props:{
id:{
type: String,
required: false
}
}

每次 navigateTo() 被调用时,'id' 在 View2 中未定义

我错过了什么,因为这在 vue2 项目中运行良好。

最佳

最佳答案

您没有在您的路径中声明 id。

{      
path: "/view2/:id", // <----
name: "view2",
component: View2,
props: true
}

关于vue.js - 为什么 Vue3 路由器不传递带有参数的 Prop ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58201409/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com