sortable浜嬩欢鐩戝惉鎬庝箞璁剧疆
鍦╒ue涓娇鐢╯ortable鎻掍欢鏉ュ疄鐜版嫋鎷芥帓搴忔椂锛屽彲浠ラ€氳繃鍦ㄧ粍浠朵腑娣诲姞sortable鐨勪簨浠剁洃鍚柟娉曟潵璁剧疆浜嬩欢鐩戝惉銆備互涓嬫槸涓€涓畝鍗曠殑绀轰緥锛?/p>
<template>
<div>
<ul ref="sortableList">
<li v-for="(item, index) in items" :key="item.id">
{{ item.name }}
</li>
</ul>
</div>
</template>
<script>
import Sortable from 'sortablejs';
export default {
data() {
return {
items: [
{ id: 1, name: 'Item 1' },
{ id: 2, name: 'Item 2' },
{ id: 3, name: 'Item 3' },
]
};
},
mounted() {
const sortableList = new Sortable(this.$refs.sortableList, {
onEnd: (evt) => {
// evt.oldIndex is the old index of the dragged element
// evt.newIndex is the new index of the dragged element
// You can update the items array based on these indexes
}
});
}
};
</script>
鍦ㄤ笂闈㈢殑绀轰緥涓紝鎴戜滑鍦ㄧ粍浠剁殑mounted鐢熷懡鍛ㄦ湡閽╁瓙涓疄渚嬪寲浜哠ortable锛屽苟璁剧疆浜唎nEnd浜嬩欢鐩戝惉鏂规硶銆傚湪onEnd浜嬩欢涓紝鎴戜滑鍙互鑾峰彇鍒拌鎷栨嫿鍏冪礌鐨勬棫绱㈠紩鍜屾柊绱㈠紩锛屽苟鏍规嵁杩欎簺绱㈠紩鏇存柊items鏁扮粍銆?/p>