h5项目引用的vant轮播图,之前正常运行。今天后端修改了一下数据结构,结果在滑动时候报错
Uncaught TypeError: Cannot read property 'width' of null
以下是解决方案:
1、给轮播图一个ref标签
<van-swipe touchable indicator-color="white" ref="swipe">
<van-swipe-item v-for="(i, index) in newBanner" :key="index">
<img :src="i" alt="" />
</van-swipe-item>
</van-swipe>
2、设置一个延时器,让其在数据渲染之后重绘轮播图
//e.banner是我的banner
this.newBanner = res.data.banner;
setTimeout(() => {
that.$refs.swipe.resize();
}, 500);
完美解决vant轮播图滑动报错问题。