English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
template code:
<template> <div class="hello"> <ul> <li v-for="(item, index) in proData"> <label for=""> <input type="checkbox" :value="index" v-model="selectArr"> </label>{{item.name}} </li>: </ul> <button type="" @click="del">Delete</<button>{{selectArr}} <label> <input type="checkbox" class="checkbox" @click="selectAll" />Select All </label> </div> </template>
script section:
<script> var proData = [{ "name": "j"1ax" }, { "name": "j"2ax" }, { "name": "j"3ax" }, { "name": "j"4ax" }] export default { name: 'hello', data() { return { proData: proData, selectArr: [] } }, created() { this.$http.get('/api/home').then(function(response) { response = response.body; this.proData = response.data; })}} }, methods: { del() { let arr = []; var len = this.proData.length; for (var i = 0; i < len; i++) { if (this.selectArr.indexOf(i) >= 0) { console.log(this.selectArr.indexOf(i)) } else { arr.push(proData[i]); } } this.proData = arr; this.selectArr = []; }, selectAll(event) { var _this = this; console.log(event.currentTarget) if (!event.currentTarget.checked) { this.selectArr = []; } else { //Implement full selection _this.selectArr = []; _this.proData.forEach(function(item, i) { _this.selectArr.push(i); }); } } } } </script>
The above-mentioned is the introduction by the editor of how to implement the full selection and multiple deletion functions using vue.js. I hope it will be helpful to everyone. If you have any questions, please leave a message, and the editor will reply to everyone in time. I would also like to express my sincere gratitude to everyone for their support of the Yelling Tutorial website!
Declaration: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#w3Please report via email to codebox.com (replace # with @ when sending an email) and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.