需求
点击按钮,然后传递ID到详情页,详情页获取ID进行查询
具体实现
在Trao中是可以通过 this.$router.params或 getCurrentInstance().router.params 来访问当前组件/页面路由的详情。 但是在Trao3.X之后官方是推荐使用getCurrentInstance()获取的
当前页
let ntUrl = "./list/list?id=" + row.id;
Taro.navigateTo({
url: ntUrl,
});
跳转目标页
由于getCurrentInstance()是Trao的api,所以需要先引入才可以使用
<script>
import { getCurrentInstance } from "@tarojs/taro";
export default {
name: "detail",
components: {},
setup() {
// 获取url传递过来的参数
let id = getCurrentInstance().router.params.id;
});
return {
};
},
};
</script>
具体参考:Trao官网