关于图片路径问题

292 阅读1分钟

转自博客【vue 关于图片路径的问题】
原文链接

如果要用v-bind去动态绑定,正常思路来说。会这样写:

   <img :src="scope.row.status1" alt="" style="width: 50px;height: 50px; ">
   
   tData: [{
                    status1:'./a.jpg'
                }]

但是在webpack中 他会被当成一个字符串来处理,并不会转换为图片的路径

正确的写法

status1: require('./a.jpg')

如果图片路径不是本地静态图片 就不需要 require 啦


<template>
    <div>
        <img width="100" height="100" :src="imgsrc1" alt="">
        <img width="100" height="100" :src="imgsrc2" alt="">
    </div>
</template>

<script>
export default {
  name: 'index',
  data () {
    return {
      imgsrc1: 'http://www.wwtliu.com/sxtstu/blueberrypai/indexImg/banner1.jpg',
      imgsrc2: require('../assets/1.jpeg')
    }
  }
}
</script>