首页 >web前端 >js教程 >在swiper中如何解决动态加载数据滑动失效的问题?

在swiper中如何解决动态加载数据滑动失效的问题?

亚连
亚连原创
2018-06-04 13:59:323650浏览

下面我就为大家分享一篇swiper 解决动态加载数据滑动失效的问题,具有很好的参考价值,希望对大家有所帮助。

两种解决方法

1、数据加载后进行swiper初始化

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 =&#39;<p class="noCollect">&#39; + resultdata.msg + &#39;</p>&#39;;
	}else{
		for(var i in dataList){
			var data = dataList[i];
			html += &#39;<p class="swiper-container artistp">&#39;
			+ &#39;<p class="swiper-wrapper">&#39;
			+ &#39;<p class="swiper-slide workp">&#39;
			+ &#39;<p class="app_inlineBlock workPic">&#39;
			+ &#39;<img class="picImg" src="&#39;+ data.artistAvatar +&#39;" />&#39;
			+ &#39;</p>&#39;+&#39;<p class="app_inlineBlock workInfo">&#39;
			+ &#39;<p class="artistName">&#39; + data.artistName + &#39;</p>&#39;
			+ &#39;<p class="workName">&#39; + data.artworkName + &#39;</p>&#39;
			+ &#39;<p class="workValue">&#39;+ data.typeName +&#39;/&#39;+ data.width + &#39;*&#39; + data.height +&#39;/&#39; +data.createYear + &#39;</p>&#39;
			+ &#39;</p><p class="app_inlineBlockRight workPrice">&#39;
			+ &#39;<p class="price">¥&#39;+ data.marketPrice +&#39;</p></p></p>&#39;
			+ &#39;<p class="swiper-slide delBtn">删除</p></p></p>&#39;;
		}
		
	}
	$("#list").append(html);
	//swiper初始化 
	var swiper = new Swiper(&#39;.swiper-container&#39;, {
		pagination: &#39;.swiper-pagination&#39;,
		slidesPerView: &#39;auto&#39;,
		paginationClickable: true,
		spaceBetween: 0
	});
}

2、swiper初始化加两行代码

swiper1 = new Swiper(&#39;.swiper-container&#39;, { 
 initialSlide :0, 
 observer:true,//修改swiper自己或子元素时,自动初始化swiper 
 observeParents:true//修改swiper的父元素时,自动初始化swiper 
});

上面是我整理给大家的,希望今后会对大家有帮助。

相关文章:

如何关闭Vue计算属性自带的缓存功能,具体步骤有哪些?

有关在Vue中使用Compass的具体方法?

利用vue2.0中swiper组件实现轮播(详细教程)

以上是在swiper中如何解决动态加载数据滑动失效的问题?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn