微信小程序购物车单选 、多选 , 解决点击后选择按钮后是否变化问题

使用uni-app 制作微信小程序 ,在做购物车的时候发现没有合适的单选和多选组件 ,然后只能自己想办法了。

我就准备了两张图片  一个选中 一个未选中

 

然后用一个三元表达式 判断展示哪张图片

:src="ischecked[index] ? '/static/check/checked.png?': '/static/check/unchecked.png'"

发现布尔值改变后页面展示按钮不会变化

checked(index) {
                this.ischecked[index] = !this.ischecked[index]
            },

然后加个刷新

checked(index) {
                this.ischecked[index] = !this.ischecked[index]

                 this.$refs.udb.refresh()
            }

这是可以展示了 但是体验很差 ,每次页面都会闪烁一下 

全选方法执行完后加个return 发现图片会变化 ,不加return就不会 有没有大佬告诉我为什么 ,单选方法加了return又不会变化 。

        checkedAll() {
                if (this.ischeckedall == false) {
                    for (var i = 0; i < this.ischecked.length; i++) {
                        if (this.ischecked[i] != true) {
                            this.ischecked[i] = true
                        }
                    }
                    this.ischeckedall = true
                    return;
                }
                if (this.ischeckedall == true) {
                    for (var i = 0; i < this.ischecked.length; i++) {
                        this.ischecked[i] = false
                    }
                    this.ischeckedall = false
                    return;
                }
            }


麻了

完全搞不懂为啥

下面这段代码 在布尔值改变后  对应的图片不会更新 

            checked(index) {
                if (this.ischecked[index]) {
                    this.ischecked[index] = false
                    this.ischeckedall = false
                    return
                }
                this.ischecked[index] = true
            },

但是加上 this.settlement() 方法后又会自动对应更新图片

            checked(index) {
                if (this.ischecked[index]) {
                    this.ischecked[index] = false
                    this.ischeckedall = false
                    this.settlement()
                    return
                }
                this.ischecked[index] = true
                this.settlement()
            },

但是 this.settlement() 方法里面没有更新数据  如下

只是进行了计算而已 

            settlement() {
                this.totalPrice = 0
                for (var i = 0; i < this.ischecked.length; i++) {
                    if (this.ischecked[i] == true) {
                        this.totalPrice += this.$refs.udb.dataList[i].goods_id[0].goods_price
                    }
                }
            }

有没有大佬懂  求教

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

NoBug.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值