Introduction
In this article, we are going to learn how we use the radio button and dropdown select in Vue.js. Radio button is an element that allows the user to select only one option from multiple options.
You can check my previous articles on Vue.js from the below mentioned links.
- Overview Of Vue.js
- Create VueJS Project Using Vue UI
- How To Fetch Data From WEB API In Vue.js Application
Prerequisites
- We should have basic knowledge of HTML and Vue.js
- Visual Studio Code editor
Create VueJS Project
Create a Vue.js project by using the following command.
vue create Dropdowndemo
Now open this project in Vs code and install bootstrap.
npm install bootstrap-vue bootstrap --save
Now open the main.js file and import bootstrap reference.
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'
Now right click on the components folder and add a new component named 'dropdowndemo.vue'. Now open dropdowndemo.vue component and add the following code.
<template>
<div id="app">
<div class="row" style="margin:10px">
<div class="col-sm-12 btn btn-info"> How To Use Dropdown And Radio Buttons In Vue.js </div>
</div>
<div class=" row col-sm-12">
<div class="col-sm-4"></div>
<div class="col-sm-4">
<select class="form-control" @change="changevalue($event)">
<option value="" selected disabled>Select Value</option>
<option v-for="data in rowData" :value="data.Id" :key="data.Id">{{ data.Name }}</option>
</select>
</div>
<div class="col-sm-4"></div>
</div>
<br>
<br>
<p v-if="seen">
<span>Selected Value: <b> {{ selectedvalue }}</b>
</span>
</p>
</div>
</template>
<script>
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'
export default {
name: 'Dropdowndemo',
data() {
return {
selectedvalue: 'No Value Selected',
seen: false,
rowData: [{
Id: "100",
Name: "Sanwar",
Age: "25",
Address: "Jaipur",
City: "Jaipur",
Salary: "500000",
Department: "IT",
}, {
Id: "2",
Name: "Nisha",
Age: "25",
Address: "C-Scheme",
City: "Jaipur",
Salary: "500000",
Department: "IT",
}, {
Id: "3",
Name: "David",
Age: "25",
Address: "C-Scheme",
City: "Jaipur",
Salary: "500000",
Department: "IT",
}, {
Id: "4",
Name: "Sam",
Age: "25",
Address: "C-Scheme",
City: "Jaipur",
Salary: "500000",
Department: "IT",
}, {
Id: "5",
Name: "Jyotsna",
Age: "25",
Address: "C-Scheme",
City: "Mumbai",
Salary: "500000",
Department: "IT",
}, {
Id: "6",
Name: "Sid",
Age: "25",
Address: "C-Scheme",
City: "Bangalore",
Salary: "500000",
Department: "IT",
}, {
Id: "7",
Name: "Chavi",
Age: "25",
Address: "C-Scheme",
City: "Noida",
Salary: "500000",
Department: "IT",
}, {
Id: "8",
Name: "Nisha",
Age: "25",
Address: "C-Scheme",
City: "Delhi",
Salary: "500000",
Department: "IT",
}]
}
},
methods: {
changevalue(event) {
this.selectedvalue = event.target.options[event.target.options.selectedIndex].text
console.log(this.selectedvalue)
this.seen = true;
}
}
}
</script>
<style></style>




Join the conversation! Your thoughts help the community grow.