问题:
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()
。这样,图片就可以显示。