vue 循環列表 jq綁定事件的問題

項目是:vue+jquery混合使用
問題:VUE循環出來的列表自動綁定一個單擊事件,但是每向上加載一次就綁定一次,導致多次綁定的數據的單擊事件就會失效,前面想過用vue傳參增加方法什麼的判斷,但是感覺那樣代碼太複雜,不想那樣搞。
解決方案:每一次進去綁定之前,都把前面一次的數據進行一個解綁處理,這樣不管如何加載,我的單擊事件的綁定都是沒有問題的。

閱讀之後希望能幫到你,謝謝閱讀!!!!

	<script type="text/javascript">
		function jqInit() {
			$(function() {
				$('.toggle-btn').unbind(); //解綁Click事件
				$('.toggle-btn').click(function() {//再進行綁定
					$(this).toggleClass('on');
					$(this).parents('.deftext').siblings('.moretext').slideToggle(200);
				})
			})
		};
	</script>


下面是VUE代碼 方法
 //獲取合同數據
						htListLoad(isUpRefresh, params) { //獲取合同數據
						if (this.firstload) {
							const layerid = layer.open({
								type: 2,
								content: '正在加載'
							});
							setTimeout(() => {
								window.alert("1111");
								this.firstload = false;
								mui('section').pullRefresh().endPullupToRefresh(false);

							}, 500)
						}

						for (let p in params) {
							this.curparam[p] = params[p];
						}

						if (!isUpRefresh) {
							this.curparam.page = 1;
							this.htlist = [];
						}

						htList1(this.curparam).then(res => {
							layer.closeAll();
							//res.data.total 獲取數據總數
							this.curparam.total = res.data.total;
							let result = res.data.rows;
							this.htlist = this.htlist.concat(result);
							for (let i in this.htlist) {
								let temp = JSON.parse(JSON.stringify(this.htlist[i]))
								for (let j in this.zh) {
									this.zh[j] += temp[j];
								}
							}

							setTimeout(() => {
								mui('section').pullRefresh().endPullupToRefresh(this.htlist.length == res.data.total);
							}, 200);
							jqInit();
						})
					},
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章