Answer the question
In order to leave comments, you need to log in
How to display data correctly when radio is selected?
Hello. How to correctly display the price when choosing a specific radio
<label v-for="(size, index) in result.sizes" class="p-1 flex size relative">
<input type="radio" v-model="result.size" :value="index" :data-size="size" v-model.number="result.indexOfSize" class="hidden">
<span class="px-2 rounded-full size active">{{ size }}</span>
</label>
<span class="text-lg md:text-xl price">{{ result.prices }}</span>
sizes: [
'256GB', '512GB'
],
prices: [
'99 999', '105 999'
],
indexOfSize: 0,
<span class="text-lg md:text-xl price">{{result[result.indexOfSize].prices}}</span>
Answer the question
In order to leave comments, you need to log in
From the array with prices, you need to pull out the element corresponding to the selected index:
<span>{{ result.prices[result.indexOfSize] }}</span>
items: [
{ size: '256GB', price: '99 999' },
{ size: '512GB', price: '105 999' },
],
index: 0,
<label v-for="(n, i) in result.items">
<input type="radio" :value="i" v-model.number="result.index">
<span>{{ n.size }}</span>
</label>
computed: {
selectedItem() {
return this.result.items[this.result.index];
},
...
<span>{{ selectedItem.price }}</span>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question