更新记录

1.6.0(2023-04-03)

升级为 uni_modules 插件


平台兼容性

使用组件

<yszyun-shopcart :goods="gooods"   @add="addCart" @dec="decreaseCart" @input="inputCart" @delAll="delAll"></yszyun-shopcart>

相关的方法

addCart: function(item) {
                // console.log('ev', JSON.stringify(item))
                if (item.count >= 0) {
                    item.count++
                    this.goods.forEach((good) => {
                        good.foods.forEach((food) => {
                            if (item.name == food.name)
                                food.count = item.count
                        })
                    })
                    // console.log('c++', JSON.stringify(item))
                } else {
                    console.log('add')
                    this.goods.forEach((good) => {
                        good.foods.forEach((food) => {
                            if (item.name == food.name)
                                Vue.set(food, 'count', 1)
                            // food.count = 1
                            // console.log('add-shop', JSON.stringify(food))
                        })
                    })
                }
            },
            decreaseCart(item) {
                if (item.count) {
                    item.count--
                    this.goods.forEach((good) => {
                        good.foods.forEach((food) => {
                            if (item.name == food.name)
                                food.count = item.count
                            // console.log('dec-shop', JSON.stringify(this.foods))
                        })
                    })
                }
            },
            inputCart: function(item) {
                if (item.count >= 0) {
                    item.count++
                    this.goods.forEach((good) => {
                        good.foods.forEach((food) => {
                            if (item.name == food.name)
                                food.count = item.count + -1
                        })
                    })
                    // console.log('c++', JSON.stringify(item))
                } else {
                    this.goods.forEach((good) => {
                        good.foods.forEach((food) => {
                            if (item.name == food.name)
                                Vue.set(food, 'count', 1)
                            // food.count = 1
                            // console.log('add-shop', JSON.stringify(food))
                        })
                    })
                }
            },
            // 清空购物车
            delAll() {
                this.goods.forEach((good) => {
                    good.foods.forEach((food) => {
                        if (food.count) {
                            food.count = 0
                            // console.log(JSON.stringify(food));
                        }
                    })
                })
            }

goods示例

gooods:[
                    {
                      "name": "热销",
                      "foods": [{
                            "name": "南瓜粥",
                            "price": 9.22,
                            "description": "食材:大米,南瓜",
                            "sellCount": 229,
                            "img": '/uni_modules/yszyun-shopcart/static/nanguaz.jpg'
                          }, {
                            "name": "小米粥",
                            "price": 9.8,
                            "description": "食材:小米",
                            "sellCount": 239,
                            "img": '/uni_modules/yszyun-shopcart/static/xiaomi.jpg'
                          },
                          {
                            "name": "油条",
                            "price": 1.88,
                            "description": "食材:油条",
                            "sellCount": 229,
                            "img": '/uni_modules/yszyun-shopcart/static/youtiao.jpg'
                        }]
                      },
                      {
                        "name": "折扣",
                        "foods": [{
                          "name": "油条1只",
                          "price": 1.88,
                          "description": "食材:油条",
                          "sellCount": 229,
                          "img": '/uni_modules/yszyun-shopcart/static/youtiao.jpg'
                        }, {
                          "name": "艇仔粥",
                          "price": 9.9,
                          "description": "食材:瘦肉,干贝,花生等",
                          "sellCount": 239,
                          "img": '/uni_modules/yszyun-shopcart/static/tingzaiz.jpg'
                        }],
                      }
                ]

说明:目前支持平台有APP、微信小程序、H5,其他平台理论上支持。

扫码添加技术微信支持,备注说明对应的插件名称

详情咨询电话: 400-008-1668

邮箱:marketing@yszyun.com

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问