[英]Vue.js: Get values of selected checkboxes
I have my own checkbox component (multi-checkbox-select from here: https://qvault.io/javascript/how-to-create-a-custom-checkbox-form-in-vue/ ).我有自己的复选框组件(从这里多复选框选择: https : //qvault.io/javascript/how-to-create-a-custom-checkbox-form-in-vue/ )。 I would like to output the selected values of the checkboxes as text, but I get only the currently selected one.
我想将复选框的选定值作为文本输出,但我只得到当前选定的值。 What am I doing wrong?
我究竟做错了什么?
<CustomCheckboxSelect
v-model="optionsSelect"
:options="options"
checked="value"
validation="required"
input-has-errors-class="is-invalid"
errors-class="invalid-feedback"
error-behavior="submit"
placeholder="Choose"
/>
<span class="test">{{ optionsSelect }}</span>
It seems that your component is emitting an input
so you need to read that in the parent您的组件似乎正在发出
input
因此您需要在父组件中读取该input
<CustomCheckboxSelect
v-model="optionsSelect"
:options="options"
checked="value"
validation="required"
input-has-errors-class="is-invalid"
errors-class="invalid-feedback"
error-behavior="submit"
placeholder="Choose"
@input="checkboxValue"
/>
and in your <script>
add a method that reads that并在您的
<script>
添加一个读取该内容的方法
methods: {
checkboxValue: function (boxValue) {
console.log(boxValue);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.