1、写在html里
<router-link :to="{path:'/goldShop/goodsInfo',query: { id:item.id }}" class="swiperBG">
2、写在js里
this.$router.push({
path: '/goldShop/allGoods'
})
this.$router.push({
path:`/goldShop/payInfo`,
query:{id:this.id,num:this.num}//带参
})
console.log(this.$route.query.id);//取值
//在新窗口中打开
let url= this.$router.resolve({
path:"/goldShop/payInfo"
})
window.open(url.href,'_black')
路由监听
methods: {
watchrouter() {//如果路由有变化,执行的对应的动作
if (this.$route.query.sort == 'goldDetail') this.tabstatus = 3
if (this.$route.query.sort == 'order') this.tabstatus = 0
if (this.$route.query.sort == 'address') this.tabstatus = 1
if (this.$route.query.sort == 'howto') this.tabstatus = 2
}
},
watch: {
$route: 'watchrouter'//路由变化时,执行的方法
},