How to select all check boxes by default in vue? select at least 4 before you can click the next step.

[1] there is such a requirement in the project, how to solve it. The default check box is all selected, or you can cancel a certain state. Select at least 4 options before you can click next. How to achieve this
html:

        <li>
          <input id="yl" type="checkbox" value="yl"  v-model="isSelected" @click="nextBtn">
          <label for="yl"></label>
        </li>
        <li>
          <input id="mk" type="checkbox" value="mk"  v-model="isSelected" @click="nextBtn">
          <label for="mk"></label>
        </li>
        <li>
          <input id="cp" type="checkbox" value="cp"  v-model="isSelected" @click="nextBtn">
          <label for="cp"></label>
        </li>
        <li>
          <input id="zj" type="checkbox" value="zj"  v-model="isSelected" @click="nextBtn">
          <label for="zj"></label>
        </li>
        <li>
          <input id="cc" type="checkbox" value="cc"  v-model="isSelected" @click="nextBtn">
          <label for="cc"></label>
        </li>
        <li>
          <input id="wl" type="checkbox" value="wl"  v-model="isSelected" @click="nextBtn">
          <label for="wl"></label>
        </li>
        <li>
          <input id="xs" checked type="checkbox" value="xs"  v-model="isSelected" @click="nextBtn">
          <label for="xs"></label>
        </li>
        <li class="choose-btn">
          <button type="button" @click="$router.back(-1)"></button>
          <button type="button" ></button>
        </li>
      </ul>

    js:
    export default {
    data () {

    return {
      checked: true,
      isSave: false,
      isSelected: []
    }

    },
    methods: {

    // checkboxclickchecboxvaluemodel
    // setTimeout
    nextBtn: function () {
      var self = this
      setTimeout(function () {
        console.log(self.isSelected)
      }, 0)
    }

    }
    }

    4


    this is the

    output from the console after selecting two items.
Nov.16,2021

isSelected has stored the selected value, so just make sure that the array is longer than 04:00 when you click next.


can declare an empty array. When you enter the page, you say that the default state is all selected, then the array is empty. When you click on the check box method, when push records an id, for the selected input in the array and finally clicks submit, you can judge the number or status of the unselected input in the array. Can you try this idea?

you can store these values in an array, such as

.
data = [{
    name: '',
    selected: false
},{
    name: '',
    selected: false
}]

then bind the selected to v-model, add click events to the checkbox, and iterate through the array with each click to know the number of selections.

Menu