Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding images to Vue Select dropdown?

I am using vue-select component as my dropdowns and giving it :options as the data to put in the dropdown. I am using it for a credit card dropdown right now and want to add the card type image in in each dropdown row. Is this possible?

like image 875
RohimL Avatar asked Apr 02 '19 16:04

RohimL


People also ask

How do I add an image to a drop down list?

Add <img> tag in dropdown content to insert image into dropdown list for each items. Note: In case the user needs the width of the content to be as wide as the dropdown button, please set the width to 100% (Set overflow: auto to get scroll on small screens).

How do you get a dropdown value from Vue?

Get Selected Value of Select Dropdown in VueCreated a select box inside the template syntax. Added an onChange() event handler. Created an options list, cars name primarily. Used the on-change method to grab the selected value using the event object.


1 Answers

You could use the scoped option slot that vue-select provides for creating custom dropdown templates.

Assuming that your options data looked like this:

options: [
  {
    title: "Visa",
    cardImage: "https://codeclimate.com/github/sagalbot/linktoimage.png"
  },
  {
    title: "Mastercard",
    cardImage: "https://codeclimate.com/github/sagalbot/linktoimage.png"
  }
];

Then you could use it as such:

<v-select :options="options" label="title">
  <template slot="option" slot-scope="option">
      <img :src="option.cardImage" />
      {{ option.title }}
  </template>
</v-select>
like image 162
Ana Liza Pandac Avatar answered Nov 15 '22 10:11

Ana Liza Pandac