今天遇到一个特别坑爹问题,页面中使用img动态绑定图片路径时总是不显示。(处理前的代码)

<div class="prod-content">
  <div class="prod-item" v-for="(item,index) in Merchant" :key="index">
    <img :src="item.imgUrl" alt="">
    <span>{{item.name}}</span>
  </div>
</div>
Merchant:[
    {imgUrl:'../../assets/image/凯叔讲故事.png',name:'凯叔讲故事'},
    {imgUrl:'../../assets/image/樊登读书.png',name:'樊登读书'},
    {imgUrl:'../../assets/image/QQ音乐.png',name:'QQ音乐'},
    {imgUrl:'../../assets/image/滴滴出行.png',name:'滴滴出行 '},
    {imgUrl:'../../assets/image/沃尔玛.png',name:'沃尔玛'},
    {imgUrl:'../../assets/image/星巴克.png',name:'星巴克'},
    {imgUrl:'../../assets/image/爱奇艺.png',name:'爱奇艺'},
    {imgUrl:'../../assets/image/腾讯视频.png',name:'腾讯视频'},
    {imgUrl:'../../assets/image/优酷.png',name:'优酷'},
    {imgUrl:'../../assets/image/携程.png',name:'携程'},
  ],

 

 

解决办法:图片链接是需要通过 require包裹。这样图片就可以正常显示啦。(网络请求的数据应该做相应的处理) 

*** 图片的路径不要出行中文,这里只是做演示

Merchant:[
  {imgUrl:require('../../assets/image/凯叔讲故事.png'),name:'凯叔讲故事'},
  {imgUrl:require("../../assets/image/樊登读书.png"),name:'樊登读书'},
  {imgUrl:require("../../assets/image/QQ音乐.png"),name:'QQ音乐'},
  {imgUrl:require("../../assets/image/携程.png"),name:'携程'},
  {imgUrl:require("../../assets/image/滴滴出行.png"),name:'滴滴出行'},
  {imgUrl:require("../../assets/image/沃尔玛.png"),name:'沃尔玛'},
  {imgUrl:require("../../assets/image/星巴克.png"),name:'星巴克'},
  {imgUrl:require("../../assets/image/爱奇艺.png"),name:'爱奇艺'},
  {imgUrl:require("../../assets/image/腾讯视频.png"),name:'腾讯视频'},
  {imgUrl:require("../../assets/image/优酷.png"),name:'优酷'},
],

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐