






















<ul ref="listRef">
<li v-for="(item,index) in dataList" :data-id="item.id" :key="item.index" class="draggable">{{item.sort}}.{{item.name}}<icon class="handle"></icon></li>
</ul>
const dataList = shallowRef([])
const listRef = ref();
onMounted(() => {
const srotableObj = new Sortable(listRef.value.$el, {
animation: 150,
handle: '.handle',
draggable: '.draggable',
onEnd: () => {
const ids = srotableObj.toArray()
ids.forEach((id, index) => {
dataList.value.find(x => x.id == id).sort = index + 1;
})
triggerRef(dataList);
}
});
}
参考文档手册 https://sortablejs.com/
或者使用 Vue.Draggable
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。