Thanks to visit codestin.com
Credit goes to coreui.io

How to handle select dropdown in Vue

Creating select dropdowns is fundamental for building user-friendly forms and filtering interfaces in Vue applications. As the creator of CoreUI, a widely used open-source UI library, I’ve implemented countless dropdown components and form controls over 25 years of development. From my expertise, the most effective approach is using v-model with the select element and v-for to generate options dynamically from data arrays. This creates reactive dropdowns that automatically update when data changes and provide seamless two-way binding.

Use v-model with select element and v-for to create reactive dropdown menus.

<template>
  <select v-model="selectedCountry">
    <option disabled value="">Choose a country</option>
    <option v-for="country in countries" :key="country.code" :value="country.code">
      {{ country.name }}
    </option>
  </select>
</template>

<script>
export default {
  data() {
    return {
      selectedCountry: '',
      countries: [
        { code: 'US', name: 'United States' },
        { code: 'CA', name: 'Canada' }
      ]
    }
  }
}
</script>

Here v-model="selectedCountry" creates two-way binding between the select element and the data property. The v-for directive generates option elements from the countries array, using :key for Vue’s reactivity and :value to set the option values. The disabled placeholder option provides user guidance when no selection is made.

Best Practice Note:

This is the same dropdown implementation pattern we use in CoreUI Vue components for consistent form controls. Always provide a disabled placeholder option for better UX, use meaningful key attributes for option elements, and consider implementing search functionality for long option lists.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
How to check if a string is a number in JavaScript
How to check if a string is a number in JavaScript

How to Open All Links in New Tab Using JavaScript
How to Open All Links in New Tab Using JavaScript

Understanding the difference between `for...in` and `for...of` statements in JavaScript
Understanding the difference between `for...in` and `for...of` statements in JavaScript

How to Achieve Perfectly Rounded Corners in CSS
How to Achieve Perfectly Rounded Corners in CSS

Answers by CoreUI Core Team