//params参数支持可传可不传,在route配置上加一个'?'就可以解决;
path:'/searchDome/:keyword?',
//支持传值为underfunded,在传值的三目中加一个underfunded
gosearch(){
this.$router.push({name:'searchDome', params:{keyword:this.searchData ||undefined}})
}
//如何携带params参数和query参数?
gosearch(){
//如果路径中有query参数,就一起带过去
if(this.$route.query){
//如果params参数不传使用undefined占位
let location ={name:'searchDome', params:{keyword:this.searchData ||undefined}}
location.query=this.$route.query
this.$router.push(location)
}
}
//如何清除页面路由传参?
//组件通信设置元数据为null,判断是否有query参数,存在携带query参数,如果不存在路由跳转指向当前页面
if(this.$route.query){
this.$router.push({name:"search",query:this.$route.query})
}else{
this.$router.push({name:"search"})
}
前端知识点----params参数可传可不传?传的值为空?
最新推荐文章于 2025-04-21 09:56:17 发布