【问题标题】:Bootstrap-Vue card component image doesn't renderBootstrap-Vue 卡片组件图像不呈现
【发布时间】:2017-07-27 04:00:28
【问题描述】:

我正在尝试在我用 Vue.js 制作的静态网站上获得一张简单的引导卡。我为此使用 Bootstrap-Vue。但是,当我使用 b-cardimg 属性时,我似乎无法显示图像。这是卡片上的文档:

https://bootstrap-vue.js.org/docs/components/card

这是我没有显示图像的代码(所有其他文本都在渲染,甚至是 github 图标)

<b-card img="`../assets/q1.png`" title="7 Little Words" class="mb-2 col-md-6">
       <!--The image above is not showing-->
  <h5 :style="{fontSize:1.3+'em', marginTop:20+'px'}">An addictive vocabulary puzzle for word nerds</h5>
  <div class="demo">
    <a href="" :style="{marginBottom:10+'px'}">VIEW DEMO</a>
  </div>
  <div class="github">
    <h4>Github</h4>
                  <!--This image below is showing-->
    <a href=""><img src="../assets/GitHub.png" alt="GitHub"></a> 
  </div>
</b-card>

我认为它必须与b-card 中的img 属性有关,但我不确定如何修复它。另外,这是我在控制台中的错误:

http://localhost:8080/assets/q1.png404(未找到)

【问题讨论】:

    标签: html twitter-bootstrap vue.js


    【解决方案1】:

    &lt;b-card&gt;组件中绑定img如下:

        <b-card img-src="../assets/q1.png" title="7 Little Words" class="mb-2 col-md-6">
            ...your markup goes here....
        </b-card>
    

    并将值为“img-src”的属性“b-card”添加到 vue-loader.conf.js 中的“transformToRequire”对象中,如下所述https://bootstrap-vue.js.org/docs/reference/images/

    例子:

    transformToRequire: {
        'video': 'src',
        'source': 'src',
        'img': 'src',
        'image': 'xlink:href',
        'b-card': 'img-src'
    }
    

    这有帮助吗?

    【讨论】:

      【解决方案2】:

      你在使用 Webkit 吗?试试:

      <b-card :img="require('../assets/q1.png')" 
              title="7 Little Words" 
              class="mb-2 col-md-6">
      

      require 确保 Webkit 在编译模板时替换资源路径。

      还要注意 img 属性之前的 : - v-bind

      的简写

      【讨论】:

      • 当我尝试这个时,它说- invalid expression: :img="require(../assets/q1.png)"
      • 我的错,路径需要用单引号括起来。
      【解决方案3】:

      我测试了代码,去掉 img 属性上多余的单引号后它工作正常。

      【讨论】:

        猜你喜欢
        • 2021-01-05
        • 2019-06-17
        • 2020-08-12
        • 2019-12-12
        • 2020-07-24
        • 1970-01-01
        • 2018-10-21
        • 2020-10-10
        • 2019-08-16
        相关资源
        最近更新 更多