关于 商品优惠立即抢购 传入数据 ID 问题

来源:13-4 购物车调试

慕小庄

2019-12-20

  methods: {
    // 立即抢购 => 加入購物車
    createCart: async function () { // 从接口取得数据
      let _this = this;
      let {status, data: {code, id}} = await this.$axios.post('/cart/create', {
        params: { // 传入数据
          id: Math.random().toString().slice(3, 9), // 对应的产品ID (一般都会在产品库中取得)
          detail: { 
            name: _this.meta.name,          // 产品名称
            price: _this.meta.biz_ext.cost, // 产品价格
            imgs: _this.meta.photos,        // 产品图片
          }
        }
      })
      if(status===200 && code===0){
        window.location.href=`/cart/?id=${id}`; // 以上都成功了,就跳转到购物车
      }else{
        console.log('error');
      }
    },

  },

快乐老师您好:
我有一个疑点想请你帮我解惑,关于 传入数据(params) 中的 id, 我将id 关掉,发现在最后购物车的部分,会没有价格和数量,但id 是一个乱数是如何取得 商品的数据?在create接口 创建购物车时,所返回的ID 是 “ let cartNo = md5(Math.random() * 1000 + time).toString() ”,所以用户端 和 接口的ID 都不一样,这样是如何串联的数据之间的关系?

写回答

1回答

快乐动起来呀

2019-12-23

这个id是模拟的,他是商品的唯一标志,这个是商品列表返回的才对

0
0

Vue全家桶+SSR+Koa2全栈开发美团网

整合大前端8项技术,全面晋级全栈工程师,毕设/面试作品

2445 学习 · 1638 问题

查看课程