赞
踩
npm install sortablejs --save
import Sortable from 'sortablejs';
主页面:
<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>
a.如果多个页面调用该页面出现无法拖动的情况,把sortId做成动态的。
如:
<div :id="dtId"></div>
<script>
data() {
return {
dtId:'sortId'
}
methods: {
init(type) {
var el = document.getElementById(this.dtId);
}
}
}
</script>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。