编程式导航

两种写法
第一种:
字符串路径

handleClick(id){

this.$router.push(`/detail/${id}`)

}

带有路径的对象
第二种:

router.push({path:'/detail/'})

命名的路由,并加上参数,让路由简历url

router.push({name:'user',params:{username:'eduardo'}})

第四种:带查询参数,结果是/register?plan=private

router.push({name:'user',query:{plan:'private'}})

补充知识点:动态路由

{
	path:'/detail/:myid',
	component:Detail
}

再detail页面中
接收路由地址上传过来的id
this.$route.params.myid

第一种写法-路由+路由参数

然后用这个参数来请求后端数据

handleClick(id){

this.$router.push(`/detail/${id}`)

}

第二种写法:路由+路由参数 对象写法(params传参)

this.$router.push({
name:"Detail",
params:{
myiid:id}

})

第三种写法:-路径+query query传参

this.$router.push({
	path:'detail',
	query:{
	myid:id
}

})
{
path:'/detail',
component:Detail
}

接收方式:

this.$route.query.myid
this.$router.back()
this.$router.go(-1)
this.$router.(1)

详情跳转详情

项目实战,当我们进入详情页时,然后通过猜你喜欢又要进入别的详情页,我们该怎么做
handleclick(){
this.KaTeX parse error: Expected 'EOF', got '}' at position 29: …/detail/6789`) }̲ watch:{ "route.params":function()
{
console.log(“猜你喜欢传来的参数”,this.$route.params.myid,)
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值