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'//路由變化時,執行的方法
},