Heim > Fragen und Antworten > Hauptteil
P粉7319775542023-08-27 16:44:30
如果你想用你自己的方法来做,你可以这样做。
export default { data() { return { filteredIngredients: [ {name: "paper", checkbox: false}, {name: "salt", checkbox: false} ] } }, methods: { checkFocus(index) { this.filteredIngredients[index].checkbox = true; }, } }
<template> <div class="list-group-item px-md-4" v-for="(ingredient,index) in filteredIngredients" :key="index"> <div class="row px-3"> <div class="col-auto"> <input class="form-check-input" type="checkbox" @keyup.enter="checkFocus(index)" v-model="ingredient.checkbox" /> </div> <div class="col ps-0"> <span class="mb-2 d-block text-gray-800"> <strong class="text-black-600">{{ingredient.name}}</strong> </span> </div> </div> </div> </template>
如果你想使用回车键来做,你可以使用@keyup.enter代替@focus。