路由传参 -vue
2024-09-01 10:53:45
参数接收
param参数 => /: => 接收参数:this.$route.params.id
query参数 => ? => 接收参数:this.$route.query.id
还有一种 meta值
路由复用
场景:当从Product/1 跳转到 Product/2 时,原来的组件实例被复用,两个路由渲染的是用一个组件,这时组件的生命周期钩子不会被二次加载;
export default {
created() {
获取参数
}
}
这里的获取参数将不会改变,相对路由参数做出变化:
export default {
watch: {
'$router' (to ,from) {
//对路由变化做出响应
}
}
}
传递参数
由于query与params传参机制不一样,造成的差异,如果要隐藏参数用params,如果强制刷新不被清除用query
通过$router中name配置:
this.$router.push({
name: 'ProductList',
query:{
CategoryID: CategoryID
}
})
路由器配置name
问号?
this.$router.push({
path: `/ProductList?CategoryID=${id}`
})
this.$router.push({
path: `/ProductList`,
query: {
CategoryID: CategoryID
}
}) <router-link v-for="item in CategoryList" v-if="item.Level === 1" :key="item.id" :to="`/ProductList?CategoryID=${item.id}`">
通过路由器配置:
export default new Router({
routes: [
{
path: '/Product/:id',
name: 'Product',
component: Product
}
]
})
1)
<router-link :to="`/Product/${item.ID}`" v-for="item in ProductList">{{ item.ProductName }}</router-link>
<router-link :to="`{name:'Product',params:${item.ID}}`" v-for="item in ProductList">{{ item.ProductName }}</router-link>
2)
this.$router.push({
path: `/ProductList/${CategoryID}`
})
最新文章
- 在一定[min,max]区间,生成n个不重复的随机数的封装函数
- .net 网络编程
- Codeforces Round #267 (Div. 2) C. George and Job DP
- empty与isset的一点使用体会
- springmvc简述
- 检测zookeeper和kafka是否正常
- 504 Gateway Time-out 和 502 Bad Gateway相关处理
- rancher 笔记 之 rancher应用中心
- 洛谷 P1093 奖学金
- CodeForces 631B Print Check
- R+大地图时代︱ leaflet/leafletCN 动态、交互式绘制地图(遍地代码图)
- 小白用阿里云搭载wordpress个人博客
- pytorch加载预训练模型参数的方式
- CMake在Visual Studio下保持目录结构
- amipy exampes
- C# ashx接收ContentType=";text/xml";类型值
- 算法笔记--java的BigInteger类及BigDecimal类
- [日常工作] SQLSERVER 数据库出问题..搜索到的有用的网页信息
- BaiduMap 鼠标绘制矩形选框四个顶角坐标的获取
- python 控制台输出带颜色的文字的方法