VUE中獲取url中的值


如圖:獲取值

一: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);
        }
      );
    },

 

是不是超級簡單,超級激動呀

 


免責聲明!

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



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