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

 

是不是超级简单,超级激动呀

 

转载于:https://www.cnblogs.com/DZzzz/p/8933646.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值