1. <template>
    2. <div class="box">
    3. <input type="checkbox" v-model="checkAll">
    4. <ul>
    5. <li v-for="(item,index) in list" :key="index">
    6. <input type="checkbox" v-model="checkList[index]">{{item}}
    7. </li>
    8. </ul>
    9. </div>
    10. </template>
    11. <script setup lang="ts">
    12. import { toRefs, reactive, computed } from "vue";
    13. const data = reactive({
    14. list:[10,20,30,40],
    15. checkList:[false,false,false,false]
    16. })
    17. let {list,checkList} = toRefs(data)
    18. const checkAll = computed({
    19. get() {
    20. return !data.checkList.includes(false)
    21. },
    22. set(newVal:boolean) {
    23. data.checkList = data.checkList.map(() => newVal)
    24. }
    25. })
    26. </script>