Radio button binding in Vue.js

in Code Write a comment

Learn how to bind a radio button in a form in Vue.js.

If you’re not using any CSS frameworks for Vue.js you need to create a custom radio button.

Let’s create a very basic example – a form that has two radio buttons “yes” and “no”.

<input type="radio" id="yes" value="true" v-model="picked">
<label for="yes">Yes</label>
<br>
<input type="radio" id="no" value="false" v-model="picked">
<label for="no">No</label>

Hi, I'm Renat 👋

 


Vue.js

new Vue({
  data: {
    picked: null
  }
})

If you want to pre-select a value, your v-model picked value should be equal to the value of the radio button, to make it selected.

If you find this post useful, please let me know in the comments below. 
Cheers,
Renat Galyamov

Want to share this with your friends?
👉renatello.com/vue-js-radio-button

PS: Make sure you check other Vue.js tutorials, e.g. vue.js scroll to top on route change, using jQuery with Vue.js (pros and cons).

A collection of UI components for
Bootstrap 4/5 and Vue.js

Get now

Write a Comment

Comment