SwipeCell 滑动单元格

关于事件传递的坑

uni-app中传递方法

  • 废话少说直接上代码
		<van-swipe-cell :async-close="true"  id="swipe-cell"  class="swiperCell" @close="onClose" :right-width="70" >
							<view class="messageInfo">
								<view class="message-title-img">
									<image src="https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640" mode=""></image>
								</view>
								<view class="message-title">
									<view class="title-name">
										小野猫
									</view>
									<view class="title-info">
										你在?
									</view>
								</view>
							</view>
							  <view class="deleteStyle" slot="right" data-right="right" >删除</view>
							</van-swipe-cell>
onClose方法,官方的方法名字不能改
		onClose(event) {
				console.log(event);
			    const { position, instance } = event.detail;
					console.log(position);
					console.log(instance);
			    switch (position) {
			      case 'left':
			      case 'cell':
			        instance.close();
			        break;
			      case 'right':
			   uni.showModal({
			       title: '提示',
			       content: '这是一个模态弹窗',
			       success: function (res) {
			           if (res.confirm) {
			               console.log('用户点击确定');
						    instance.close();
			           } else if (res.cancel) {
			               console.log('用户点击取消');
						    instance.close();
			           }
			       }
			   })
				   
			        break;
			    }
			  }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
可以使用以下代码实现表格多个单元格滑动选择的功能: ```javascript let isMouseDown = false; let startRowIndex, startCellIndex, endRowIndex, endCellIndex; const cells = document.querySelectorAll('table td'); // 鼠标按下事件 document.addEventListener('mousedown', (event) => { isMouseDown = true; startRowIndex = event.target.parentNode.rowIndex; startCellIndex = event.target.cellIndex; }); // 鼠标移动事件 document.addEventListener('mousemove', (event) => { if (!isMouseDown) return; endRowIndex = event.target.parentNode.rowIndex; endCellIndex = event.target.cellIndex; selectCells(); }); // 鼠标松开事件 document.addEventListener('mouseup', () => { isMouseDown = false; }); // 选择单元格 function selectCells() { for (let i = 0; i < cells.length; i++) { const cell = cells[i]; const rowIndex = cell.parentNode.rowIndex; const cellIndex = cell.cellIndex; const isBetweenRows = (startRowIndex <= rowIndex && rowIndex <= endRowIndex) || (endRowIndex <= rowIndex && rowIndex <= startRowIndex); const isBetweenCells = (startCellIndex <= cellIndex && cellIndex <= endCellIndex) || (endCellIndex <= cellIndex && cellIndex <= startCellIndex); if (isBetweenRows && isBetweenCells) { cell.classList.add('selected'); } else { cell.classList.remove('selected'); } } } ``` 这段代码会对页面上所有的表格单元格添加多选功能。当用户按下鼠标时,会记录下当前单元格的行和列索引,当用户移动鼠标时,会根据当前单元格的行和列索引来选择多个单元格并高亮显示。最后,当用户松开鼠标时,多选功能结束。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值