vueで全選択多選択を実現
一、全選択枠にクリックイベントをバインドする
HTML:
JS:
二、単独で選択をカスタマイズする場合
HTML:
JS:
HTML:
JS:
chooseAllCart() {
// , ,
this.chooseAll = !this.chooseAll;
//
for (var i = 0; i < this.shopcartList.length; i++) {
this.shopcartList[i].choose = this.chooseAll;
}
},
二、単独で選択をカスタマイズする場合
HTML:
-
{{item.goodsEntity.name}}
JS:
chooseOne(index) {
// ,
this.shopcartList[index].choose = !this.shopcartList[index].choose;
, ,
for (var i = 0; i < this.shopcartList.length; i++) {
if (this.shopcartList[i].choose == false) {
this.chooseAll = false;
break;
}
}
, i break, true,
if (i == this.shopcartList.length) {
this.chooseAll = true;
}
},