首頁  >  文章  >  web前端  >  vue.js中如何取得url的值

vue.js中如何取得url的值

coldplay.xixi
coldplay.xixi原創
2020-11-11 16:00:043241瀏覽

vue.js中取得url值的方法:1、在【main.js】中寫入【path: '/goodsinfo/:goodsId'】;2、在目前檔案中設定程式碼為【< ;router-link :to="'/goodsinfo/' subitem.a】。

vue.js中如何取得url的值

【相關文章推薦: vue.js

vue.js中取得url值的方法:

一:main.js中寫入

vue.js中如何取得url的值

const router = new VueRouter({
    routes: [
        {
            path: &#39;/goodsinfo/:goodsId&#39;,
            component: goodsinfo
        },
    ]
})

二:在目前檔案中設定

vue.js中如何取得url的值

<template>
<div>
<router-link :to="&#39;/goodsinfo/&#39;+ subitem.artID"  class="">
    <div class="img-box">
        <img   v-lazy =subitem.img_url alt="vue.js中如何取得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中的值

vue.js中如何取得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);
        }
      );
    },

#相關免費學習推薦:JavaScript(影片)

以上是vue.js中如何取得url的值的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
上一篇:vue.js怎麼用jq下一篇:vue.js怎麼用jq