如何在Vue中實(shí)現(xiàn)全選/反選?針對這個(gè)問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡單易行的方法。

創(chuàng)新互聯(lián)建站堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站建設(shè)、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的寧城網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
首先就是自己創(chuàng)建一個(gè)input,正在mx.txt的前方添加一個(gè)input:CheckBox。在v-model加上你每次創(chuàng)建出來的mx.check
最重點(diǎn)就在于forEach遍歷,出來的都是當(dāng)前的。
有些人不注意的一點(diǎn),為什么data里面沒有check:[]這樣的出現(xiàn)。
data里的是實(shí)時(shí)監(jiān)控,你點(diǎn)一次自動(dòng)將所有的check都變成了true。
<template>
<div class="check">
<button @click="checkAll">全選</button>
<br>
<input type="text" v-model="txt" @keyup.enter="ck" />
<ul>
<li v-for="(mx, index) in list" :key="index">
<input type="checkbox" v-model="mx.check" /> {{mx.txt}}
</li>
</ul>
</div>
</template><script>
export default {
data() {
return {
txt: "",
list: []
}
},
methods: {
ck() {
this.list.push({
txt: this.txt,
check: false
})
this.txt = ""
},
checkAll() {
this.list.forEach((mx) => {
mx.check = !mx.check
})
}
}
}
</script><style lang="less">
.check {
cursor: pointer;
button {
cursor: pointer;
border: 0;
padding: 10px 30px;
background: #000;
color: #fff;
border-radius: 100px;
margin-bottom: 10px;
outline: none;
}
input {
padding: 15px;
width: 300px;
border: 0;
box-shadow: 0 0 15px #ccc;
}
ul {
width: 300px;
padding: 0;
cursor: pointer;
box-shadow: 0 0 15px #ccc;
min-height: 300px;
padding: 15px;
list-style: none;
li {
cursor: pointer;
margin-bottom: 12px;
>input {
padding: 0;
width: auto;
}
}
}
}
</style>關(guān)于如何在Vue中實(shí)現(xiàn)全選/反選問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。
網(wǎng)站標(biāo)題:如何在Vue中實(shí)現(xiàn)全選/反選
分享地址:http://www.yijiale78.com/article36/gddhsg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、全網(wǎng)營銷推廣、虛擬主機(jī)、、用戶體驗(yàn)、網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)