VueJS 在 v-model 中反转值

Ton*_*y S 2 javascript boolean vue.js v-model

这是我的代码:

<input
   v-model="comb.inactive"
   type="checkbox"
   @click="setInactive(comb.id_base_product_combination)"
>
Run Code Online (Sandbox Code Playgroud)

我需要在 v 模型上应用comb.inactive 的反转。

这是我尝试过的:

<input
    v-model="comb.inactive == 1 ? 0 : 1"
    type="checkbox"
    @click="setInactive(comb.id_base_product_combination)"
>



<input
    v-model="comb.inactive == 1 ? false : true"
    type="checkbox"
    @click="setInactive(comb.id_base_product_combination)"
>
Run Code Online (Sandbox Code Playgroud)

你还有其他想法吗?

Ada*_*rrh 6

考虑使用true-valuefalse-value作为快捷方式:

<input
    v-model="comb.inactive"
    type="checkbox"
    :true-value="false"
    :false-value="true"
>
Run Code Online (Sandbox Code Playgroud)

或者在这种情况下,您可能正在寻找交替整数,您可以直接设置它们。

<input
    v-model="comb.inactive"
    type="checkbox"
    :true-value="1"
    :false-value="0"
>
Run Code Online (Sandbox Code Playgroud)