下面的代码包含用于拖放的部分。div拖动块,该块需要拖动,但在第一次拖动时不起作用,它不会掉落。从第二次拖动开始,它开始下降。
https://github.com/kutlugsahin/vue-smooth-dnd
<div>
<Container
@drop="onDrop"
lock-axis="y"
drag-class="drag-div"
drop-class="drag-div"
drag-handle-selector=".shelf-icon"
:get-ghost-parent="getGhostParent"
>
<Draggable v-for="(link,index) in quick_links" :key="link.name">
<div class="drag-block">
<div class="order-number">{{ index + 1 }}</div>
<div class="content-block">
<div class="mx-ellipsis">{{ link.name }}</div>
<small class="mx-color-secondary mx-ellipsis" style="width:
250px;">{{ link.url }}</small>
</div>
<div class="shelf-icon">
<i class="micon-handle-horizontal sort-icon"></i>
</div>
</div>
</Draggable>
</Container>
</div>
有一个解决此问题的方法,当在vue实例的已挂接钩子中初始化包装实例时,我们可以使用一些延迟。下面的代码显示了示例谢谢。
<template>
<display-panel @closed="closeDialog">
<template slot="content">
<div>
<div class="section-title">{{$t('edit_display_order')}}</div>
<div class="divider branding-color" />
<div
class="display-order-edit-info"
></div>
<div class="drag-drop-container">
<Container
v-if="showDragContainer"
ref="quickLinkDragDrop"
@drop="onDrop"
lock-axis="y"
drag-class="drag-div"
drop-class="drag-div"
drag-handle-selector=".shelf-icon"
:get-ghost-parent="getGhostParent"
>
<Draggable v-for="(link,index) in items" :key="link.name">
<div class="drag-block">
<div class="order-number">{{ index + 1 }}</div>
<div class="content-block">
<div class="ellipsis">{{ link.name }}</div>
<small class="color-secondary ellipsis" style="width: 250px;">{{ link.url }}</small>
</div>
<div class="shelf-icon">
<i class="micon-handle-horizontal sort-icon"></i>
</div>
</div>
</Draggable>
</Container>
</div>
</div>
</template>
</display-panel>
</template>
<script>
import { Container, Draggable } from 'vue-smooth-dnd'
export default {
name: 'DragComponent',
components: {
Container,
Draggable
},
props: {
itemLinks: {
type: Array,
default: () => []
}
},
mounted() {
setTimeout(() => {
this.showDragContainer = true
}, 300)
}
}
</script>