Vue---this.$route和this.$router這兩個對象--都需要在router.js 中配置


// 注意: 在 this 這個組件身上,有 this.$route 和 this.$router

// this.$route 是專門用來獲取路由中參數的;

// this.$router 是專門來實現編程式導航的;

// 注意:this.$route和this.$router這兩個對象

// this.$route是路由參數對象,所有路由中的參數,params,query都屬於他

// this.$router 是一個路由(導航對象),用它方便的使用js 代碼,實現路由的前進,后退,跳轉到新的url地址

 

1.最簡單的

點擊事件--@click="goDesc"

methods: {
  
   goDesc() {
     this.$router.push("路徑/home/goodsdesc/" + 參數this.goodsinfo.id);
  }
}
 rputer.js--配置
{ path: '/home/goodsinfo/:id', component: GoodsInfo, props: true },
  2.首頁tbar跳轉---
標簽跳轉<router-link class="" to="路徑/home"></router-link>
需要在router.js配置路由
<router-link tag="div" :to="'/home/goodsinfo/' + item.id" class="goods-item" v-for="item in goodslist" :key="item.id">
 接收:data(){
  return{
    id:this.$route.params.id
  }
}
3.在router.js中國配置路由的時候給組件定義名字屬性
// 啟用 props 來接收路由的參數
{ path: '路徑/home/goodscomment/:id', component: 文件名字GoodsComment, props: true, name: '定義的名字goodscmt' }
 this.$router.push({
        name: "goodscmt",
        params: { id: this.goodsinfo.id }
      });
 


免責聲明!

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



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