vue.js - 将图像添加到 Vue Select 下拉菜单?
问题描述
我使用vue-select
组件作为我的下拉列表,并将其:options
作为要放入下拉列表的数据。我现在将它用于信用卡下拉菜单,并希望在每个下拉行中添加卡片类型图像。这可能吗?
解决方案
您可以使用提供创建自定义下拉模板的作用域option
插槽。vue-select
假设您的options
数据如下所示:
options: [
{
title: "Visa",
cardImage: "https://codeclimate.com/github/sagalbot/linktoimage.png"
},
{
title: "Mastercard",
cardImage: "https://codeclimate.com/github/sagalbot/linktoimage.png"
}
];
然后你可以这样使用它:
<v-select :options="options" label="title">
<template slot="option" slot-scope="option">
<img :src="option.cardImage" />
{{ option.title }}
</template>
</v-select>
推荐阅读
- json - 如何使用 kotlinx.serialization 部分解码 JSON 字符串?
- node.js - express-mutler 总是保存到临时文件夹
- r - 在 R 中读取 CSV 文件时移动列的问题
- react-hooks - React Konva 中的舞台宽度和高度是否有任何限制?
- node.js - 无法在 mac 终端上安装 npm /react /node js
- javascript - 点击一个简单的按钮时页面刷新?
- javascript - 如何在使用 jquery 的数据表中查看复选框是否已切换并据此执行操作?
- sql - 有没有办法在 ado .net 中使用完全限定的 sql 列名?
- go - KrakenD 插件读取配置设置
- android - Comletable.create 的 RxJava Completable 行为{}