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


    使用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
                        }
                    }
                }

    有没有大佬懂  求教

  • 相关阅读:
    【C++基础】9. 数组
    2023版 STM32实战10 内部Flash读写
    alsa pcm接口之阻塞和非阻塞打开和异步通知模式
    《Effective C++》知识点(4)--设计与声明
    java 每种设计模式的作用,与应用场景
    基于SSM的图书进销存管理系统
    世界环境日 | 周大福用心服务推动减碳环保
    Android Studio Iguana | 2023.2.1版本
    docker 命令
    【Unity3D】卷轴特效
  • 原文地址:https://blog.csdn.net/qq_61672548/article/details/126071495