jeudi 9 juin 2022

"v-model" with checkboxes but the data is "1" or "0" not "true" or "false"

Because of some reason on the backend, they use 0 or 1 and not false or true for booleans.

So, when I try to use the boolean data from API, TS complains:

// settings.crawl_on outputs 0 or 1
<input
 v-model=“settings.crawl_on”
 type="checkbox"
/>

I tried adding the below code it doesn't work either:

true-value="1"
false-value="0"

TS says:

(property) InputHTMLAttributes.checked?: any[] | Set | Booleanish Type 'number' is not assignable to type 'any[] | Set | Booleanish'.ts(2322)runtime-dom.d.ts(629, 3): The expected type comes from property 'checked' which is declared here on type 'ElementAttrs'

Is there a way to override this or what is the correct use?




Aucun commentaire:

Enregistrer un commentaire