[Vuejs]-How to use ternary operator to set radio input attribute in Vue.js

0👍

You can just pass conditions to :checked or :disabled and reuse everything else.

<input type="radio"
       v-on:input="changed(question.Question.ID,index)" 
       v-bind:class="{wrongAnswerInput: !question.Correct && question.AnswerGiven==(index+1)}"
       class="form-check-input" 
       :value="index" 
       :name="question.Question.ID" 
       :checked="isChecked"
       :disabled="isDisabled"
>

isChecked and isDisabled could be computed properties for example. Or you can write conditions directly in template.

Ternary could be used too if you really want it (but I believe that you don’t need it here), e.g.

<input type="radio"
       :disabled="someCondition ? someAnotherCondition : yetAnotherCondition"
>

See also:

Leave a comment