vue的路由帶參數和取參數,watch路由監聽


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

  },


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM