vue3使用vuedraggable
时间: 2023-10-02 20:09:04 浏览: 115
Vue3中使用vuedraggable是一种在前端开发中实现拖拽功能的方法。根据引用,vuedraggable适合有1-3年工作经验的前端人员使用。如果在安装过程中出现报错"Cannot read property 'header' of undefined",可以尝试安装最新版本的vuedraggable,通过命令行执行npm i -S vuedraggable@next。这样可能可以解决该报错问题,参考引用提供的解决方案。
要在Vue3中使用vuedraggable,可以按照以下方式编写代码,参考引用提供的示例代码:
```javascript
<template>
<draggable v-model="myArray" group="people" @start="drag=true" @end="drag=false" item-key="id">
<template #item="{element}">
<div>{{element.name}}</div>
</template>
</draggable>
</template>
<script lang="ts">
import { defineComponent, reactive, toRefs } from 'vue'
import draggable from 'vuedraggable'
export default defineComponent({
components: {
draggable
},
setup () {
const data = reactive({
drag: false,
myArray: [
{ id: 1, name: 'Jenny' },
{ id: 2, name: 'kevin' },
{ id: 3, name: 'lili' }
]
})
return {
...toRefs(data)
}
}
})
</script>
```
以上代码中,通过import导入了vuedraggable组件,并在template中使用draggable标签来实现拖拽功能。在setup函数中,使用reactive将数据进行响应式处理,并通过v-model绑定到draggable组件上,实现了列表的拖拽功能。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [vue3中使用vuedraggable](https://download.csdn.net/download/digital_AI/87823951)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [Vue3 使用 vuedraggable](https://blog.csdn.net/lhz_333/article/details/123403911)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文