【问题标题】:Inserting images inside the bootstrap-vue select options在 bootstrap-vue 选择选项中插入图像
【发布时间】:2019-04-05 23:31:49
【问题描述】:

有没有办法在Bootstrap-vue select下拉列表中插入图片,如下图所示?

【问题讨论】:

    标签: javascript vue.js vuejs2 vue-component bootstrap-vue


    【解决方案1】:

    是的,可以通过用<b-dropdown-item> 包裹img 标记来做到这一点,例如:

          <b-dropdown-item> <img scr="..."  /></b-dropdown-item>
    

    new Vue({
      el: '#app'
    
    });
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>Document</title>
      <link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
      <link rel="stylesheet" href="style.css">
      <link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
      <link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.css" />
    
      <!-- Add this after vue.js -->
      <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script>
      <script src="//unpkg.com/babel-polyfill@latest/dist/polyfill.min.js"></script>
      <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
      <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
      <script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.js"></script>
    
    </head>
    
    <body>
    
      <div id="app">
    
        <b-dropdown id="ddown1" text="Dropdown Button" class="m-md-2">
          <b-dropdown-item>
            <img src="https://cdn4.buysellads.net/uu/1/21673/1538677471-digitalocean-260x200-light_1_.png" alt="" border="0" height="50" width="65" style="max-width: 130px;">
          </b-dropdown-item>
          <b-dropdown-item> <img src="https://cdn4.buysellads.net/uu/1/21673/1538677471-digitalocean-260x200-light_1_.png" alt="" border="0" height="50" width="65" style="max-width: 130px;"></b-dropdown-item>
          <b-dropdown-item> <img src="https://cdn4.buysellads.net/uu/1/21673/1538677471-digitalocean-260x200-light_1_.png" alt="" border="0" height="50" width="65" style="max-width: 130px;"></b-dropdown-item>
          <b-dropdown-divider></b-dropdown-divider>
          <b-dropdown-item>Something else here...</b-dropdown-item>
          <b-dropdown-item disabled>Disabled action</b-dropdown-item>
        </b-dropdown>
      </div>
    
    
    </body>
    
    </html>

    【讨论】:

    • 用于显示链接和操作,例如在菜单中创建导航链接,不能像 中那样选择它们
    • Dropdowns 可以通过一些 javascript 逻辑转换为 Selects,并使用当前选择的值更新下拉按钮的内容。
    【解决方案2】:

    我不认为你可以使用 bootstrap-vue 来实现这一点,因为它使用原生选择输入字段,但你可以使用 vue-select 并且它非常简单: https://sagalbot.github.io/vue-select/docs/Advanced/Templating.html

    【讨论】:

    • 玛丽娜是正确的。 &lt;b-form-select&gt; 是带有子 &lt;option&gt; 元素的 CSS 样式原生 &lt;select&gt;
    猜你喜欢
    • 2019-05-23
    • 2020-07-29
    • 2021-07-25
    • 2013-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-06
    • 2020-05-11
    相关资源
    最近更新 更多