编程式路由导航

message.vue
<
template> <div> <ul> <li v-for="(message,index) in messages" :key="message.id"> <router-link :to="'/home/message/detail/'+message.id">{{message.title}}</router-link> <button @click="pushShow(message.id)">push查看</button> <button @click="replaceShow(message.id)">replace查看</button> </li> </ul> <button @click="$router.back()">回退</button> <hr/> <router-view></router-view> </div> </template> <script> export default{ data(){ return{ messages:[] } }, mounted(){ setTimeout(()=>{ const messages=[ { id:1, title:'message01' }, { id:2, title:'message02' }, { id:3, title:'message03' }, ] this.messages = messages },300) }, methods:{ pushShow(id){ this.$router.push('/home/message/detail/'+id) }, replaceShow(id){ this.$router.replace('/home/message/detail/'+id) } } } </script> <style> </style>
相关API
1) this.$router.push(path): 相当于点击路由链接(可以返回到当前路由界面)
2) this.$router.replace(path): 用新路由替换当前路由(不可以返回到当前路由界面)
3) this.$router.back(): 请求(返回)上一个记录路由
4) this.$router.go(-1): 请求(返回)上一个记录路由
5) this.$router.go(1): 请求下一个记录路由

转载于:https://www.cnblogs.com/quitpoison/p/9994705.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值