vant库 van-image标签 引用本地图片

问题:
vant中的van-image组件的src参数默认为图片的网络链接(如下所示)

<van-image
  width="100"
  height="100"
  src="https://img.yzcdn.cn/vant/cat.jpeg"
/>

当要引用本地的图片时,直接写图片的路径在vue项目中会刷不出图片(但用 <img> 标签可以显示 )。

解决方法:

<van-swipe :autoplay="3000" >
   <van-swipe-item v-for="(image, index) in imageList" :key="index">
     <img :src="image" style="width:100%;height:150px;" />
   </van-swipe-item>
 </van-swipe>
data () {
    return {
      isShow:false,
      pingan:"",
      times:"",
      content:{title: '填报须知',content: '欢迎ssss'},
      imageList: [
        require('../../../static/images/1.png'),
        require('../../../static/images/2.png'),
        require('../../../static/images/3.jpg'),
      ],
    active:1,
    notificationList:[]
    }
  },

如上所示,在图片的链接外包上一层 require() 。这样,图片就可以显示。

发布了81 篇原创文章 · 获赞 18 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_43542074/article/details/100537554