在VUE(inertiajs) / tailwind中的复选框切换为“ true”始终提交。
我有一个内置在VUE(Ineriajs) /尾风中的切换复选框组件,每当我提交表单时,值始终是正确的。
这是组件的代码:
<template>
<div class="form-check form-switch mt-5 form-inline first:mt-0">
<label v-if="label" class="form-label sm:w-20">{{ label }} - this is {{ checked }}</label>
<input type="checkbox" class="form-check-input mr-0 ml-3" :value="checked" :v-model="checked" :checked="checked" @change="onChange" :id="id"/>
</div>
</template>
<script>
import { v4 as uuid } from 'uuid'
export default {
props: {
id: {
default() {
return `checkbox-${uuid()}`
},
},
active: Boolean,
error: String,
label: String,
checked: Boolean,
},
data() {
return {
checked: this.active
}
},
methods: {
onChange() {
this.checked = !this.checked;
this.$emit('input', this.checked);
}
},
}
</script>
并称为:
<Checkbox label="Active" :active="active" />
<script>
import Checkbox from '@/components/Checkbox/Checkbox'
export default {
components: {
Checkbox,
},
props: {
user: Object,
active: Boolean,
},
data() {
return {
active: this.user.active == 0 ? false : true,
}
},
</script>
切换时,正在更新检查值时,但是每当我提交表格时,提交的值始终是“ true”的,请任何人建议。
谢谢
I have a toggle checkbox component built in Vue (IneriaJS) / Tailwind, when ever I submit the form the value is always true.
Here is the code for the component:
<template>
<div class="form-check form-switch mt-5 form-inline first:mt-0">
<label v-if="label" class="form-label sm:w-20">{{ label }} - this is {{ checked }}</label>
<input type="checkbox" class="form-check-input mr-0 ml-3" :value="checked" :v-model="checked" :checked="checked" @change="onChange" :id="id"/>
</div>
</template>
<script>
import { v4 as uuid } from 'uuid'
export default {
props: {
id: {
default() {
return `checkbox-${uuid()}`
},
},
active: Boolean,
error: String,
label: String,
checked: Boolean,
},
data() {
return {
checked: this.active
}
},
methods: {
onChange() {
this.checked = !this.checked;
this.$emit('input', this.checked);
}
},
}
</script>
And is called:
<Checkbox label="Active" :active="active" />
<script>
import Checkbox from '@/components/Checkbox/Checkbox'
export default {
components: {
Checkbox,
},
props: {
user: Object,
active: Boolean,
},
data() {
return {
active: this.user.active == 0 ? false : true,
}
},
</script>
When toggling the checked value is being updated but whenever I submit the form the value submitted is always "true" please can anyone advise.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您对发射什么都不做。将
@input =“ yourcheckboxvariable = $ event”
放在您的&lt;复选框.../&gt;
中,并用变量做点事。 )You do nothing with your emit. Put an
@input="yourCheckboxVariable = $event"
to your<Checkbox ... />
and do something with the variable. ;)