就下面幾步,簡單實現!
<input type="checkbox" name="quanxuan" id="quanxuan" @click="checkAll">全選
//全選設置一個函數
<div class="lei" v-for="list in 10" :key="list">
<input type="checkbox" ref="che" name="quanxuan" id="quanxuan">
</div>//加上 ref
//函數遍歷
methods:{
checkAll(){
this.$refs.che.filter(item=>{
item.checked = !item.checked;
})
}