I am trying to enter a conditional for v-model but it is not working can someone please tell me what's wrong?
In the template I have the exact same conditional for value that must be displayed and that works, why is it not working for v-model.
Here is a button that displays the current rating and if there is no current rating it displays 0.
<button
type="button"
class="rateBtn"
@click="showRating(post.id)"
>
{{ post.rating == null ? 0 : post.rating[0] }}
</button>
The exact same ternary operator for the following v-model gives me an error:
VueCompilerError: v-model value must be a valid JavaScript member expression.
Here is the Vue part:
<div class="ratingStars">
<div class="rating flex">
<div
class="star"
v-for="index in stars"
:key="index"
>
<input
type="radio"
name="stars"
:value="index"
v-model="
post.rating == null ? 0 : post.rating[0]
"
@change="ratePost"
/><label>☆</label>
</div>
</div>
Because if the button shows 0 (there isn't any ratings yet) then I get an error:
Uncaught (in promise) TypeError: post.rating is null
What is wrong with my v-model conditional please?