1

How can I get the value of a radio input and pass it to a function using @click in Vue.js. I actually want to do something like this:

<input type="radio" name="phone" :value="mobile.value" @click = "setPrice(value)">

What is the right syntax?

2 Answers 2

3

For what your asking click here to see the answer

Checkout this straightforward example how input radio works with vue.js

<input type="radio" id="one" value="One" v-model="picked">
<label for="one">One</label>
<br>
<input type="radio" id="two" value="Two" v-model="picked">
<label for="two">Two</label>
<br>

and the script:

export default {
  data: {
    return {
      picked: 'One'
    }
  }
}
Sign up to request clarification or add additional context in comments.

3 Comments

This just captures the value of the radio input. What I actually need is to get that value, pass it to a function in a store.js and that functions updates some other value in the store.state.
Hmm ok.I answered how you can do this and made an example to jsfiddle.
Thank you, I had the same question and it was referencing the event object that I was missing. Now it works.
3

Just provide the function name:

@click="setPrice"

You should then have access to the value:

function setPrice(event) {
  const value = event.target.value;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.