vue2.0如何选中当前获取当前数据

图片描述

实现了多选效果,想实现选中当前获取价格卡住了~如何判断当前是否已经checked?根据双向数据绑定,当ischeckdate 数组中存在这个value时,就checked。而一开始点击时数组总是为空~

多选的实现效果如下:
methods: {

checkedAll () {
        let ischeckdate = [];
            if (!this.checkAll) {
                this.cartProducts.forEach((cartProduct) => {
                    ischeckdate.push(cartProduct.id);
                });
            }
            this.ischeckdate = ischeckdate;
        }}

},
watch: {

        'ischeckdate': function () {
            if (this.cartProducts.length === this.ischeckdate.length) {
                this.checkAll = true;
            } else {
                this.checkAll = false;
            }
        },
        checkAll (yes) {
            this.checkAll = yes;
        }
    }
阅读 2.6k
1 个回答

根据你的描述文字判断问题为:如何判断当前是否已经checked?
答案是根据双向数据绑定,当ischeckdate 数组中存在这个value时,就checked
over

推荐问题