Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Show Selected Flag Country in Vue

When the country is selected, the country flag must be displayed in select option. I need to do that in Vue.

new Vue({
el: '#app',
vuetify: new Vuetify(),
data: {
select: null,
countries: [
  {
    name: "Albania",
    flag: "em-flag-al"
  },
  {
    name: "Anguilla",
    flag: "em-flag-ai"
  }
 ],
 }
 })


<div id="app">
 <v-app class="container">
<v-select
  v-model="select"
  :items="countries"
  label="Select"
  item-text="name"
>
  <template v-slot:item="slotProps" >
    <i :class="['mr-2', 'em', slotProps.item.flag]"></i>
    {{slotProps.item.name}}
  </template>
 </v-select>
 </v-app>
 </div>

Or you can refer to https://codepen.io/aaha/pen/ZEbRwpy?editors=1010

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use another slot for the selection 🙂

   <template v-slot:selection="slotProps">
     <i :class="['mr-2', 'em', slotProps.item.flag]"></i>
       <span>{{ slotProps.item.name }}</span>
   </template>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading