用v-model绑定一个数组在多选上时 会按照多选的选中状态在数组中添加或删除该选项的value值`
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="app">
<button :check="check" @click="ch">全选</button>
<ul>
<li v-for="(item,index) in arr" :key="index">
<input type="checkbox" name="" id="" :value="item" v-model="arr1">
{{item}}
</li>
</ul>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.js"></script>
<script>
var vm = new Vue({
el : ".app",
data:{
arr:["a","b","c","d"],
check : false,
arr1:[]
},
watch: {
check (){
// this.ckeck ? this.arr1 = ["a","b","c","d"] : this.arr1 = [];
if(this.check){
this.arr1 = ["a","b","c","d"]
}else{
this.arr1 = [];
}
}
},
methods: {
ch (){
this.check = !this.check;
console.log(this.check)
}
}
})
</script>
</body>
</html>