图片引入不显示问题

图片放在 assets目录下 和static 目录下
  • 固定的引入(不使用v-bind)
<img src="../assets/logo.png">
  • 把图片放static 目录,直接通过data引入
// template
<img v-bind:src=imgSrc>
// srcipt
export default {
  data () {
    return {
      imgSrc: '../static/launch.png'
    };
  }
};

或者不通过data,直接在html中引入

//template
<ul class="index-board-list">
        <li class="board-item" v-for="(item,index) in boardList" :class="[{'line-last':index % 2 != 0},'index-board-' + item.id]">
          <img :src="'../../static/images/'+(index+1)+'.png'">
          <p>{{index}}</p>
          <div class="board-item-right">
            <p>{{ item.title }}</p>
            <p>{{ item.description }}</p>
            <button class="buy_now">立即购买</button>
          </div>
        </li>
      </ul>
//script
export default {
  data() {
    return {
      boardList: [
        {
          title: "开放产品",
          description: "开放产品是一款开放产品",
          id: "car",
          toKey: "analysis",
          saleout: false,
          // src: "../../static/images/1.png"
        },
        {
          title: "品牌营销",
          description: "品牌营销帮助你的产品更好地找到定位",
          id: "earth",
          toKey: "count",
          saleout: false,
          // src: "../../static/images/2.png"
        },
        {
          title: "使命必达",
          description: "使命必达快速迭代永远保持最前端的速度",
          id: "loud",
          toKey: "forecast",
          saleout: true,
          // src: "../../static/images/3.png"
        },
        {
          title: "勇攀高峰",
          description: "帮你勇闯高峰,到达事业的顶峰",
          id: "hill",
          toKey: "publish",
          saleout: false,
          // src: "../../static/images/4.png"
        }
      ]
    }
  }
};
  • 如果放在其它目录(如assets目录),直接通过data引入,则需要如下引入
require('../assets/launch.png') 或者 import logo from '../assets/logo.png'

如:

// template
<img v-bind:src=imgSrc>
// srcipt
export default {
  data () {
    return {
      imgSrc: require('../assets/launch.png')
    };
  }
};
import logo from '../assets/logo.png
// template
<img v-bind:src=imgSrc>
// srcipt
export default {
  data () {
    return {
      imgSrc: logo
    };
  }
};
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,178评论 19 139
  • 第一次坐爸爸的车 睡醒了 张开睡眼朦胧的双眼 这是哪儿 发现不是我熟悉的大床 不是我的小摇篮 不是我常睡的那张软软...
    野渡游人阅读 1,630评论 0 0
  • 画这副画时,仿佛自己就坐在窗边。窗外,雪将落未落。窗内,炉火哔剥,明明又灭灭。竹炉汤沸时,有人恰好在对面落座。也不...
    浅野微山阅读 1,706评论 0 4

友情链接更多精彩内容