学习使用vue实现规格选择实例(二)

本文介绍如何使用Vue实现商品规格选择功能,通过点击触发蒙层展示,动态更新单价和库存。涉及两个JSON数据源:indexGoodsShow.json和getGoodsSku.json,分别用于初始数据和点击后的详细信息。在请求数据并赋值给skuArr后,讨论了如何展示淘宝式的 price 区间链接生成逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

源码
https://blog.youkuaiyun.com/qq_39019768/article/details/85629189

点击出现蒙层样式实现
在这里插入图片描述

<template>
  <div class="cab-common cab-food" @click="addCart">
    <div class="item">
      <div class="describe">
        <span class="first">机上餐食</span>
        <p class="second">Restaurant</p>
      </div>
      <div v-if="is_sku" class="specification_mask2">
        <div class="specification_com2" @click.stop="is_sku==false">
          <a class="sku-close" @click="cancelMask" aria-label="关闭">
            <i class="iconfont icon-chahao"></i>
          </a>
          <div class="number-line">
            <label for="number">您的座位号</label>
            <span class="J_limitTxt limit-txt"></span>
            <div class="number">
              <input id="number" type="number" v-model="this.$route.query.seat">
            </div>
          </div>
          <cube-button @click="sku_addCart" :primary="true">提交</cube-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      is_sku: false, // 规格弹窗
      skuArr: [],
      selectArr: [], // 存放被选中的值
      shopItemInfo: {} // 存放要和选中的值进行匹配的数据
    }
  },
  created: function() {
    var that = this
    // 商家推荐
    this.axios.get('/api/getgoods', function(res) {
      console.log('eee')
    })
  },
  methods: {
    addCart() {
      console.log('111')
      this.is_sku = true
      this.getGoodsSku()
    },
    // 点击蒙层取消
    cancelMask: function() {
      this.is_sku = false
    }
  }
}
</script>
<style lang="stylus" >
.item {
  width: 100%;
  text-align: center;
}

.specification_mask2 {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
}

.specification_com2 {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background: #fff;
}

.choose_sku2 {
  max-height: 300px;
  overflow: scroll;
}

.sku_specification2 {
  box-sizing: border-box;
  padding: 10px;
}
.sku-close {
  display block
  text-align right
  padding 10px
}
.sku_title2 {
  font-size: 15px;
  height: 0.5rem;
  line-height: 0.5rem;
}

.sku_ul2 {
  display: flex;
  flex-wrap: wrap;
}

ol, ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.productActive {
  background: #ffd100;
}
</style>

先上效果图
在这里插入图片描述
在这里插入图片描述

这里点击绿色,单价和库存变了
那么,它的内部逻辑究竟是怎么实现的呢?
项目里面涉及两个json数据
indexGoodsShow.json 这个是刚点进页面获取的数据
getGoodsSku.json 这个是点击加号以后渲染到页面的数据
点击加号以后显示的价钱和库存都是之前请求的indexGoodsShow.json里面的数据,而图片和名称是getGoodsSku.json里面的
在这里插入图片描述
在这里插入图片描述
这里的skuArr怎么来的呢?
发起请求,去请求json数据 ,成功以后的res赋给that.skuArr
在这里插入图片描述
在这里插入图片描述

这里有一个问题:淘宝上面的价格区间是怎么显示的呢?
这个地址怎么做出来的 https://oem.mobzhifu.com/Uploads/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值