使用vue.js實(shí)現(xiàn)checkbox的全選和多個(gè)的刪除功能
template代碼:
<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">刪除</button>{{selectArr}}
<label>
<input type="checkbox" class="checkbox" @click="selectAll" />全選
</label>
</div>
</template>
script部分:
<script>
var proData = [{
"name": "j1ax"
}, {
"name": "j2ax"
}, {
"name": "j3ax"
}, {
"name": "j4ax"
}]
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 { //實(shí)現(xiàn)全選
_this.selectArr = [];
_this.proData.forEach(function(item, i) {
_this.selectArr.push(i);
});
}
}
}
}
</script>
以上所述是小編給大家介紹的使用vue.js實(shí)現(xiàn)checkbox的全選和多個(gè)的刪除功能,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
vue3中調(diào)用api接口實(shí)現(xiàn)數(shù)據(jù)的渲染以及詳情方式
這篇文章主要介紹了vue3中調(diào)用api接口實(shí)現(xiàn)數(shù)據(jù)的渲染以及詳情方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08
Vue3?封裝一個(gè)支持輸入和單/多選InputSelect組件-Antd詳解
Antd的Select組件默認(rèn)不支持作為輸入框使用或手動(dòng)添加選項(xiàng),為了實(shí)現(xiàn)這一功能,我們封裝了一個(gè)通用組件,支持單選和多選模式,并允許用戶在組件失焦時(shí)手動(dòng)輸入選項(xiàng),主要通過定義searchText存儲(chǔ)輸入數(shù)據(jù),感興趣的朋友跟隨小編一起看看吧2024-09-09
關(guān)于Vue中echarts響應(yīng)式頁面變化resize()的用法介紹
Vue項(xiàng)目中開發(fā)數(shù)據(jù)大屏,使用echarts圖表根據(jù)不同尺寸的屏幕進(jìn)行適配,resize()可以調(diào)用echarts中內(nèi)置的resize函數(shù)進(jìn)行自適應(yīng)縮放,本文將給大家詳細(xì)介紹resize()的用法,需要的朋友可以參考下2023-06-06
vue實(shí)現(xiàn)自定義"模態(tài)彈窗"組件實(shí)例代碼
頁面中會(huì)有很多時(shí)候需要彈窗提示,我們可以寫一個(gè)彈窗組件,下面這篇文章主要給大家介紹了關(guān)于vue實(shí)現(xiàn)自定義"模態(tài)彈窗"組件的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2021-12-12
解決vue頁面刷新vuex中state數(shù)據(jù)丟失的問題
這篇文章介紹了解決vue頁面刷新vuex中state數(shù)據(jù)丟失的問題,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-01-01
在瀏覽器console中如何調(diào)用vue內(nèi)部方法
這篇文章主要介紹了在瀏覽器console中如何調(diào)用vue內(nèi)部方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07

