Home > Web Front-end > JS Tutorial > body text

How to use el-checkbox to select all (code)

不言
Release: 2018-10-23 16:36:31
forward
5333 people have browsed it

The content of this article is about using el-checkbox to achieve full selection (code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Recently received a request in the company, add batches, select all and delete books in favorites
Implementation idea: click on select all to change the checked of the item, change the checked of the item, and make it more convenient All items are checked to change the selectAll

1) The basic function of this component has been implemented. The checkbox uses vant-ui. Since the official website does not have a demo with such a function, I implemented it according to the above ideas, but it is a headache. It only has a change event, which means that when the checked item is changed by selecting all, the change of the item will be triggered. At the same time, the change of the item will trigger the event in the change of all selection, thus creating an infinite loop.

2) Use native click instead of change event

3) Use el-checkbox. Fortunately, the project also uses element-ui. I checked the implementation plan, although I have some doubts about its val
Note: The data bound to el-checked must be in the data from the beginning and cannot be added later, which may cause clicks to fail sometimes, hahaha~~

<el-checkbox v-model="selectAll" @change="selectAllFunc"></el-checkbox>
<el-checkbox  v-model="item.checked" @change="selectProduct"></el-checkbox>
selectProduct(val) {
  for(let i = 0,len = this.collectionlist.length;i < len;i ++){
    if(!this.collectionlist[i].checked){
      this.selectAll = false;
      return false;
    }
  }
  this.selectAll = true;
}
selectAllFunc(val){
  this.collectionlist.map((item,i)=>{
    item.checked = val;
  })
}
Copy after login

The above is the detailed content of How to use el-checkbox to select all (code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!