Home  >  Q&A  >  body text

Display selected country flags in Vue

After selecting a country, the national flag must be displayed in the selection options. I need to do this 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

P粉464082061P粉464082061296 days ago425

reply all(1)I'll reply

  • P粉087074897

    P粉0870748972023-12-29 14:16:42

    You can use another slot to choose :)

    reply
    0
  • Cancelreply