uniapp实现相关元素的拖拽排序兼容app和H5

//先下载sortablejs插件

<view class="tag">
		<view class="title">个人特色:<text  @click="inputDialogToggle" style="display: inline-block; margin-right: 20rpx;float: right;background-color:#ff9d00;padding: 10rpx 30rpx;border-radius: 20rpx; color: #fff;">添加</text></view>
		<view class="tag-list" id="foo">
		<view class="tag-item" v-for="(item,index) in tags" :key="index">{{item}}
			<uni-icons class="icon" type="clear" color="rgb(249 22 22)" size="15"  @click="delTag(index)"></uni-icons>
		</view>
		</view>
			
</view>

.tag{
			background-color: #fff;
			padding: 20rpx;
			margin-bottom: 20rpx;
			box-shadow: 4rpx 4rpx 6rpx 4rpx #eee;
			border-radius: 16rpx;
			.tag-list{
				display: flex;
				flex-wrap: wrap;
				.tag-item{
					position: relative;
					padding: 10rpx 10rpx 10rpx 10rpx;
					margin: 20rpx;
					height: 20rpx;
					line-height: 20rpx;
					background-color: #fff;
					border: 2rpx solid  #e43d33;
					color: #e43d33;
					font-size: 24rpx;
					.icon{
						position: absolute;
						top: -10rpx;
						right: -18rpx;
						 background-color: white;
					}
					
				}
				
			}
			.title{
				color: #606266;
				height: 72rpx;
			}
		}

//h5中
	mounted() {
			// #ifdef H5
		Sortable.create(document.getElementById("foo"), {
			animation: 150, //动画参数
			onAdd: function(evt) {
				//拖拽时候添加有新的节点的时候发生该事件
				console.log("onAdd.foo:", [evt.item, evt.from]);
			},
			onUpdate: function(evt) {
				//拖拽更新节点位置发生该事件
				console.log("onUpdate.foo:", [evt.item, evt.from]);
			},
			onRemove: function(evt) {
				//删除拖拽节点的时候促发该事件
				console.log("onRemove.foo:", [evt.item, evt.from]);
			},
			onStart: function(evt) {
				//开始拖拽出发该函数
				console.log("onStart.foo:", [evt.item, evt.from]);
			},
			onSort: function(evt) {
				//发生排序发生该事件
				console.log("onSort.foo:", [evt.item, evt.from],evt.from.innerText);
				// 索引5移到索引4的位置,索引变化
				// evt.newDraggableIndex -- 4
				// evt.newIndex  --4
				// evt.oldDraggableIndex  --5
				// evt.oldIndex   --5
			},
			onEnd: function(evt) {
				//拖拽完毕之后发生该事件
				console.log("onEnd.foo:", [evt.item, evt.from]);
			},
			})
				// #endif
		},

//在app中要再写一个script   lang="renderjs"
<script module="Sortable" lang="renderjs">
	// #ifdef APP-PLUS
	import Sortable from 'sortablejs'
	export default {
		mounted(){
			Sortable.create(document.getElementById("foo"), {
					animation: 150, //动画参数
					onAdd: function(evt) {
						//拖拽时候添加有新的节点的时候发生该事件
						console.log("onAdd.foo:", [evt.item, evt.from]);
					},
					onUpdate: function(evt) {
						//拖拽更新节点位置发生该事件
						console.log("onUpdate.foo:", [evt.item, evt.from]);
					},
					onRemove: function(evt) {
						//删除拖拽节点的时候促发该事件
						console.log("onRemove.foo:", [evt.item, evt.from]);
					},
					onStart: function(evt) {
						//开始拖拽出发该函数
						console.log("onStart.foo:", [evt.item, evt.from]);
					},
					onSort: function(evt) {
						//发生排序发生该事件
						console.log("onSort.foo:", [evt.item, evt.from],evt.from.innerText);
						// 索引5移到索引4的位置,索引变化
						// evt.newDraggableIndex -- 4
						// evt.newIndex  --4
						// evt.oldDraggableIndex  --5
						// evt.oldIndex   --5
					},
					onEnd: function(evt) {
						//拖拽完毕之后发生该事件
						console.log("onEnd.foo:", [evt.item, evt.from]);
					},
					
			})
		},
	}
	// #endif
</script>

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值