I have checkbox using element-plus:
<el-checkbox
v-model="slotProps.action.check_control"
:checked="slotProps.action.check_control"
size="large"
class="ml-4"
:id="slotProps.action.id"
@change="checkControl(slotProps.action.id, slotProps.action.check_control)"
/>
And I make api call with this function: checkControl.
const checkControl = (id, controlled) => {
loading.value = true
if (controlled === true) {
controlled = 1
} else {
controlled = 0
}
ApiService.postTest('api...', {
jar_id: id,
check_control: controlled
})
.then((res) => {
loading.value = false
})
.catch((e) => {
loading.value = false
console.log(e)
})
}
whats wrong is after the page is rendered, if the checkbox is checked, I click the checkbox, but it checks it again instead of unchecked.
I am not sure if this related with element plus, but here is the documentation about it: https://element-plus.org/en-US/component/checkbox.html#checkbox-attributes
is short for
See form input bindings.
In the above example,
fooshould be reactive.Meaning: "do not use both
v-modeland:checkedon same<input type="checkbox" />!"If removing
:checkeddoesn't solve the problem, please provide more detail about howslotProps.action.check_controlgets populated in the context of your component. Currently, thejslogic you are showing does not seem related to what you're passing to the<input />.To set the
checkedvalue of the<input />programatically, use onlyv-modeland set whateverv-modelpoints to astrue, initially.