[Vue warn]: Invalid prop: type check failed for prop "value". Expected Boolean, Array, got String.
-
When using q-checkbox, I get the above error when outputting the value from the db, which will be a string of 0 or 1. How can I change this so I don’t get the above error?
Here is my code that results in the error above, it is part of a loop that prints values from my array:
<tr v-if="post.meta_key === 'ma_share'"><td class="labels">SHARING:</td><td class="values"> <q-checkbox v-model="post.meta_value" v-bind:true-value="1" v-bind:false-value="0" /> </td><td></td></tr>
If I use the standard vue checkbox, it works without any error:
<tr v-if="post.meta_key === 'ma_share'"><td class="labels">SHARING:</td><td class="values"><input type="checkbox" v-model="post.meta_value" v-bind:true-value="1" v-bind:false-value="0" > </td><td></td></tr>
-
FYI I have tried it both with and without the v-bind attributes…
-
There are no
true-value
andfalse-value
props. Model needs to be a Boolean OR an Array of Strings (current ‘selected’ values) along withval
prop. You could transform the data you get from server to be a Boolean.What you want with the two new props would be a new request.
-
my data is a 0 or a 1, and I have now changed my API to not quote the numbers, but I am still getting an error. Are you saying I can’t have a 0 or 1, I have to send “true” or “false”?
-
I have tried things like this, but they don’t work:
<q-checkbox v-model="Boolean(post.meta_value)" />
-
Ok, I have my API returning “true” and “false” and it STILL doesn’t work. It is back to the same error. Any suggestions?
-
I ended up having to rewrite my API (in php) to deal with 1 and 0 in the db to make it work for this component. In case anyone is wondering, here is what it looked like:
$myarrayeverythingbutbooleans = firstsql $justbooleans = booleansonlysql $jbtotalarray = array(); foreach ($justbooleans as $jbpush) { if (($jbpush['meta_value']=="1")) { $jbpush['meta_value'] = true; } else { $jbpush['meta_value'] = false; } $jbtotalarray[] = $jbpush; } $mergedwithtrue = array_merge($myarrayeverythingbutbooleans,$jbtotalarray); return $mergedwithtrue;