<template>
<div class="box">
<input type="checkbox" v-model="checkAll">
<ul>
<li v-for="(item,index) in list" :key="index">
<input type="checkbox" v-model="checkList[index]">{{item}}
</li>
</ul>
</div>
</template>
<script setup lang="ts">
import { toRefs, reactive, computed } from "vue";
const data = reactive({
list:[10,20,30,40],
checkList:[false,false,false,false]
})
let {list,checkList} = toRefs(data)
const checkAll = computed({
get() {
return !data.checkList.includes(false)
},
set(newVal:boolean) {
data.checkList = data.checkList.map(() => newVal)
}
})
</script>