如圖:獲取值
一:main.js中寫入
const router = new VueRouter({ routes: [ { path: '/goodsinfo/:goodsId', component: goodsinfo }, ] })
二:在當前文件中設置
<template> <div>
<router-link :to="'/goodsinfo/'+ subitem.artID" class=""> <div class="img-box"> <img v-lazy =subitem.img_url> </div> <div class="info"> <h3>{{subitem.artTitle}}</h3> <p class="price"> <b>{{subitem.sell_price}}</b>元</p> <p> <strong>庫存 {{subitem.stock_quantity}}</strong> <span>市場價: <s>{{subitem.market_price}}</s> </span> </p> </div> </router-link>
</div>
</template>
三:在跳轉后的文件中獲取url中的值
// 獲得商品評論數據 getCommentByPage() { const url = `site/comment/getbypage/goods/${ this.$route.params.goodsId }?pageIndex=${this.pageIndex}&pageSize=${this.pageSize}`; this.$axios.get(url).then( res => { this.comment = res.data; }, err => { console.log(err); } ); },
是不是超級簡單,超級激動呀