在vue3中使用vuedraggable会报 Cannot read property 'header' of undefined 这个错误

其实我们只要安装最新版的vuedraggable就能解决这个问题

npm i -S vuedraggable@next

然后再引入插件使用即可

<template>
  <div>
    <draggable
      v-model="myArray"
      group="people"
      @start="drag = true"
      @end="drag = false"
      item-key="id"
    >
      <template #item="{element}">
        <div>{{ element.name }}</div>
      </template>
    </draggable>
  </div>
</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: [
        { people: 'cn', id: 10, name: '小明' },
        { people: 'cn', id: 20, name: '小红' },
        { people: 'zh', id: 30, name: 'Karen' },
        { people: 'zh', id: 40, name: 'Mary' }
      ]
    })
    return { ...toRefs(data) }
  }
})
</script>

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐