在vue3中使用sortablejs实现拖拉拽功能
<template>
<div class="about">
<div class="left">
<ul id="left-list" ref="leftList">
<li>123</li>
<li>456</li>
<li>789</li>
</ul>
</div>
<div class="right">
<ul id="right-list" ref="rightList">
<li>666</li>
</ul>
</div>
</div>
</template>
<script setup>
import { onMounted, ref } from "vue";
import Sortable from "sortablejs";
onMounted(() => {
const leftList = document.getElementById("left-list");
const rightList = document.getElementById("right-list");
console.log(leftList, rightList);
Sortable.create(leftList, {
group: "shared",
animation: 150,
onEnd: function (evt) {
const item = evt.item;
rightList.appendChild(item);
},
});
Sortable.create(rightList, {
group: "shared",
animation: 150,
onEnd: function (evt) {
const item = evt.item;
leftList.appendChild(item);
},
});
});
</script>
<style lang="scss" scoped>
* {
padding: 0;
margin: 0;
list-style: none;
}
.about {
display: flex;
justify-content: space-around;
.left {
padding: 10px;
background-color: skyblue;
}
.right {
padding: 10px;
background-color: pink;
}
}
</style>