Home >Web Front-end >JS Tutorial >Full selection and inverse selection in vue
This time I will bring you the full selection and reverse selection in vue. What are the precautions for selecting all and reverse selection in vue. The following is a practical case, let's take a look.
I won’t say any more nonsense and let’s get straight to the code!
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <p id="app"> <p style="padding-left: 20px"> <ul style="margin-bottom: 20px"> <li v-for="(item, index) in proData"> <input type="checkbox" :value="index" v-model="selectArr">{{item.name}} </li> </ul> <label> <input type="checkbox" @click="selectAll" :checked="checked"/>全选 </label> </p> </p> </body> <script src="https://cdn.jsdelivr.net/npm/vue"></script> <script type="text/javascript"> var vm = new Vue({ el : "#app", data : { proData: [ { "name": "张三" }, { "name": "李四" }, { "name": "王五" }, { "name": "赵六" } ], selectArr: [], checked : false }, watch : { selectArr(curVal){ if(curVal.length == this.proData.length){ this.checked = true }else{ this.checked = false } } }, methods: { selectAll(event){ if (!event.currentTarget.checked) { this.selectArr = []; } else { //实现全选 this.selectArr = []; this.proData.forEach((item, i) =>{ this.selectArr.push(i); }); } } } }) </script> </html>
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
How NodeJS implements the WebSocket function
CDN accelerates the react webpack packaging file process
The above is the detailed content of Full selection and inverse selection in vue. For more information, please follow other related articles on the PHP Chinese website!