Home >Web Front-end >JS Tutorial >How to solve the problem of sliding failure of dynamically loaded data in swiper?
Below I will share with you an article about swiper that solves the problem of sliding failure of dynamically loaded data. It has a good reference value and I hope it will be helpful to everyone.
Two solutions
1. Initialize swiper after loading the data
success:function(result){ var resultdata =eval("("+result+")"); if(resultdata.status == 1){ var dataList = resultdata.data; currentPage = resultdata.currentPage; pageCount = resultdata.pageCount; var html = ""; if(pageCount == 0){ html ='<p class="noCollect">' + resultdata.msg + '</p>'; }else{ for(var i in dataList){ var data = dataList[i]; html += '<p class="swiper-container artistp">' + '<p class="swiper-wrapper">' + '<p class="swiper-slide workp">' + '<p class="app_inlineBlock workPic">' + '<img class="picImg" src="'+ data.artistAvatar +'" />' + '</p>'+'<p class="app_inlineBlock workInfo">' + '<p class="artistName">' + data.artistName + '</p>' + '<p class="workName">' + data.artworkName + '</p>' + '<p class="workValue">'+ data.typeName +'/'+ data.width + '*' + data.height +'/' +data.createYear + '</p>' + '</p><p class="app_inlineBlockRight workPrice">' + '<p class="price">¥'+ data.marketPrice +'</p></p></p>' + '<p class="swiper-slide delBtn">删除</p></p></p>'; } } $("#list").append(html); //swiper初始化 var swiper = new Swiper('.swiper-container', { pagination: '.swiper-pagination', slidesPerView: 'auto', paginationClickable: true, spaceBetween: 0 }); }
2. Add two lines of code to swiper initialization
swiper1 = new Swiper('.swiper-container', { initialSlide :0, observer:true,//修改swiper自己或子元素时,自动初始化swiper observeParents:true//修改swiper的父元素时,自动初始化swiper });
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
How to turn off the caching function of Vue calculated properties. What are the specific steps?
What are the specific methods of using Compass in Vue?
Use the swiper component in vue2.0 to implement carousel (detailed tutorial)
The above is the detailed content of How to solve the problem of sliding failure of dynamically loaded data in swiper?. For more information, please follow other related articles on the PHP Chinese website!