两种写法
第一种:
字符串路径
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,)
}
}