I am currently utilizing the ionic
framework with vuejs
.
The product page I created does not include any form elements.
On the page, there is a radio button for selecting the size of the product.
How can I retrieve the selected value from the radio button created using ion-radio
when the add to cart
button is pressed on that page?
I am still learning vue.js
. In the past, in jQuery, I would get the value using the following method:
$('input[name=radioName]:checked').val()
How do I extract the selected radio button value in vuejs
???
Below is the corresponding HTML section:
<ion-list v-if="product.size_maps">
<ion-radio-group>
<ion-row>
<ion-col
v-for="size in product.size_maps"
:key="size.id"
size="6"
id="product_size"
>
<ion-item>
<ion-label class="ion-no-margin">
{{ size.size.text }}
</ion-label>
<ion-radio slot="start" :value="size.size.id"></ion-radio>
</ion-item>
</ion-col>
</ion-row>
</ion-radio-group>
</ion-list>
I have implemented a method named addToCart
:
methods: {
addToCart(event) {
console.log(event);
// Obtain radio button value here
}
}
Here is how I invoked the addToCart function within the button:
<ion-button
color="primary"
fill="solid"
expand="block"
size="default"
v-on:click="addToCart"
>
Add To Cart
</ion-button>
Edit:
I attempted to use v-model
to fetch the data. Unfortunately, without an available input
tag, I couldn't apply it.
If I included the v-model
in the ion-radio
tag, then all radio buttons end up getting checked.