Bacancy Technology
Bacancy Technology represents the connected world, offering innovative and customer-centric information technology experiences, enabling Enterprises, Associates and the Society to Rise™.
12+
Countries where we have happy customers
1050+
Agile enabled employees
06
World wide offices
12+
Years of Experience
05
Agile Coaches
14
Certified Scrum Masters
1000+
Clients projects
1458
Happy customers
Artificial Intelligence
Machine Learning
Salesforce
Microsoft
SAP
October 26, 2023
You can get a selected value in a select element in VueJs in two ways. First using the v-model directive to bind the selected option of a < select > element to a data property. Second, you can listen to the change event on a select element to get the latest selected value. Heres are the examples for both options.
<template> <div> <select v-model="selectedOption" @change="logSelectedOption"> <option value="option1">Option 1</option> <option value="option2">Option 2</option> <option value="option3">Option 3</option> </select> </div> </template> <script> export default { data() { return { selectedOption: null, }; }, methods: { logSelectedOption() { console.log('Selected Option:', this.selectedOption); }, }, }; </script>
<template> <div> <select @change="logSelectedOption($event)"> <option value="option1">Option 1</option> <option value="option2">Option 2</option> <option value="option3">Option 3</option> </select> </div> </template> <script> export default { data() { return { selectedOption: null, }; }, methods: { logSelectedOption(value) { console.log('Selected Option:', value); this.selectedOption = value; }, }, }; </script>