[英]Get the list of all selected check boxes with Vue.js
How can I get a list of all check boxes that I selected with Vue?如何获取我使用 Vue 选择的所有复选框的列表? This is my HTML which works and shows me a list of my products with a checkbox.
这是我的 HTML,它可以工作并向我显示带有复选框的产品列表。
<li v-for="(product, index) in products">
<input :id="product.slug" :value="product.id" name="product" type="checkbox" />
<label :for="product.slug"><span></span></label>
</li>
What I want is that when I click on a button, it fetches all check boxes that I selected.我想要的是,当我单击一个按钮时,它会获取我选择的所有复选框。 And give me all the values.
并给我所有的价值观。 But I can't figure out how to do it, because it'll break when I even try to add a
v-model
to the checkbox.但是我不知道该怎么做,因为当我什至尝试向复选框添加
v-model
时它会中断。
Just bind every checkbox value
with a product and the v-model
to the array checkedProducts
只需将每个复选框
value
与产品和v-model
绑定到数组checkedProducts
<li v-for="(product, index) in products">
<input :id="product.slug" :value="product" name="product" type="checkbox" v-model="checkedProducts" />
<label :for="product.slug"><span></span></label>
</li>
...
data(){
return{
...
checkedProducts:[]
....
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.