SoFunction
Updated on 2025-04-05

Vue's commonly used sample code for selecting all/unselecting

There are many ways to execute all selections of CheckBox in Vue

I think this is the easiest way to understand and the fastest speed!

The first thing is to create an input yourself and add an input: CheckBox in front of it. Add the v-model you create every time

The most important thing is forEach traversal, and all the things that come out are current.
Some people don’t pay attention to why there is no check:[] in data.
Data is real-time monitoring. You click once to automatically turn all checks into true.

<template>
 <div class="check">
 <button @click="checkAll">Select all</button>
 <br>
 <input type="text" v-model="txt" @="ck" />
 <ul>
 <li v-for="(mx, index) in list" :key="index">
 <input type="checkbox" v-model="" /> {{}}
 </li>
 </ul>
 </div>
</template>
<script>
 export default {
 data() {
 return {
 txt: "",
 list: []
 }
 },
 methods: {
 ck() {
 ({
  txt: ,
  check: false
 })

  = ""
 },
 checkAll() {

 ((mx) => {
   = !
 })

 }
 }
 }
</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>

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.