sorttable 拖拽使用笔记

sortable.js中文文档

1.npm安装方式

npm install sortablejs --save

2.vue导入

import Sortable from 'sortablejs';

3.上下拖拽示例

主页面:

<template>
  <div class="app-container">
	<div>
	 <search-sort ref="searchSortRef"/>
	 <el-button type="primary" @click="initSearchSort">排序设置</el-button>
	</div>
  </div>
</template>

<script>
import SearchSort from "@/views/system/notice/searchSort";

export default {
 name: "Notice",
 components: {
   SearchSort,
 },
 data() {
   return {
   };
 },
 methods: {
   initSearchSort(){
     this.$refs.searchSortRef.init(1);
   },
 }
</script>

引用页面:

<template>
	<el-dialog title="查询排序" :visible.sync="open" width="800px" append-to-body :close-on-click-modal="false">
	   <el-form ref="form" :model="form" :rules="rules" label-width="80px">
	     <div id="sortId">
	        <div data-id="1">item 1</div>
	        <div data-id="2">item 2</div>
	        <div data-id="3">item 3</div>
	     </div>
	   </el-form>
	   <div slot="footer" class="dialog-footer">
	     <el-button type="primary" @click="submitForm">确 定</el-button>
	     <el-button @click="cancel">取 消</el-button>
	   </div>
	 </el-dialog>
</template>

<script>
import Sortable from 'sortablejs';

export default {
  name: "searchSort",
  components: {
    Sortable
  },
  data() {
    return {
    	open:false,
      	//类型:1.记账页面
      	type: undefined,
    };
  },
  created() {
  },
  methods: {
    init(type) {
    	this.type = type;
    	this.open=true;
	    this.$nextTick(function(){
	       var el = document.getElementById('sortId');
	      //设置配置
	      var ops = {
	        animation: 1000,
	        //拖动结束
	        onEnd: function (evt) {
	          console.log(evt);
	          //获取拖动后的排序
	          var arr = sortable.toArray();//输出的值是data-id的值
	          alert('获取拖动后的排序'+ JSON.stringify(arr));
	        },
	      };
	      //初始化
	      var sortable = Sortable.create(el, ops);
	  })
    },
    cancel(){
		this.open=false;
	},
	submitForm(){
	}
  }
};
</script>

4.总结

a.如果多个页面调用该页面出现无法拖动的情况,把sortId做成动态的。
如:

<div :id="dtId"></div>
<script>
data() {
  	return {
		dtId:'sortId'
	}
	methods: {
	    init(type) {
	    	var el = document.getElementById(this.dtId);
	    }
    }
}
</script>

5.el-drawer 抽屉拖拽实例参考如下:

https://www.jb51.net/article/204167.htm

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值