swiper组件数据加载慢怎么办?

小程序 文章 2021-03-09 11:21 992 0 全屏看文

AI助手支持GPT4.0

swiper组件数据加载慢怎么办?What should I do if swiper component data is slow to load?

swiper组件数据加载慢怎么办?

用swiper在页面上渲染数据非常慢,数组长度75就渲染的很慢,求教有没有办法优化体验

It's very slow to render data on the page with swiper, and it's very slow to render when the array length is 75. Is there any way to optimize the experience

回答:

Brother斌🎈:

好家伙 swiper居然一次性渲染75条

给你个方案,创建一个listCopy数组,里面设置和list一样的数量的空字符串对象数组,比如['','','','',....]

然后一开始给数组前两个值赋值,比如listCopy[0]=list[0];listCopy[1]=list[1]

然后在swiperChange里面,每次change的时候删掉一个listCopy已经显示的值,再加上一个未显示的值,比如第一次change删掉listCopy[0],再使listCopy[2]=list[2];

这样能始终保持swiper只渲染两条数据,当然可以不止2条,4、5、6条都可以,wx:for也要改成循环listCopy

微盟:

使用懒加载的方式进行优化

卢霄霄:

有点多。。如果没有一次滑一片的需求的话,可以只渲染3个,然后每次滚动都去设置列表和当前项

-EOF-

AI助手支持GPT4.0