// 注意: 在 this 這個組件身上,有 this.$route 和 this.$router
// this.$route 是專門用來獲取路由中參數的;
// this.$router 是專門來實現編程式導航的;
// 注意:this.$route和this.$router這兩個對象
// this.$route是路由參數對象,所有路由中的參數,params,query都屬於他
@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 }
});
