VUEJS 3可拖动问题
我正在使用“ Vue-Dragable-Next”:“^2.1.1”。
当我尝试拖动时,什么都不会发生。
我在html中看到:
<div class="flex m-10" data-v-52c58f0f="">
<draggable list="[object Object],[object Object],[object Object],[object Object]" data-v-52c58f0f="">
<div class="list-group-item bg-gray-300 m-1 p-3 rounded-md text-center" data-v-52c58f0f="">John</div>
<div class="list-group-item bg-gray-300 m-1 p-3 rounded-md text-center" data-v-52c58f0f="">Joao</div>
<div class="list-group-item bg-gray-300 m-1 p-3 rounded-md text-center" data-v-52c58f0f="">Jean</div>
<div class="list-group-item bg-gray-300 m-1 p-3 rounded-md text-center" data-v-52c58f0f="">Gerard</div>`
</draggable>
</div>
当我实现这样的代码时:
import {vuedraggablenext}来自“ vue-draggable-next”;
组件:{ 可拖动:vuedraggablenext },
和
列表:[
{name:'john',id:1}, {名称:'joao',id:2}, {名称:'jean',id:3}, {名称:'Gerard',ID:4}, ],,
和我已经尝试的模板:
&lt; draggable class =“ dragarea list-group w-full”:list =“ list” @change =“ log”&gt; &lt; div class =“ List-Group-Item BG-Gray-300 M-1 P-3圆形MD文本中心” v-for =“列表中的元素” :key =“ element.name” &gt; {{element.name}} &lt;/div&gt; &lt;/draggable&gt;
这是:
<draggable
:list="list"
:disabled="!enabled"
item-key="name"
class="list-group"
ghost-class="ghost"
:move="checkMove"
@start="dragging = true"
@end="dragging = false"
>
<template #item="{ element }">
<div class="list-group-item" :class="{ 'not-draggable': !enabled }">
{{ element.name }}
</div>
</template>
</draggable>
在我使用的情况下
&lt; template #item =“ {element}”&gt;
什么都没有显示,在另一种情况下,没有什么是可拖动的。
该组件已加载,我可以看到Chrome的VUE扩展名:
有人知道为什么它不起作用吗?
I'm using VueJS 3 with "vue-draggable-next": "^2.1.1".
Nothing happens when I try to drag.
I see in the HTML this:
<div class="flex m-10" data-v-52c58f0f="">
<draggable list="[object Object],[object Object],[object Object],[object Object]" data-v-52c58f0f="">
<div class="list-group-item bg-gray-300 m-1 p-3 rounded-md text-center" data-v-52c58f0f="">John</div>
<div class="list-group-item bg-gray-300 m-1 p-3 rounded-md text-center" data-v-52c58f0f="">Joao</div>
<div class="list-group-item bg-gray-300 m-1 p-3 rounded-md text-center" data-v-52c58f0f="">Jean</div>
<div class="list-group-item bg-gray-300 m-1 p-3 rounded-md text-center" data-v-52c58f0f="">Gerard</div>`
</draggable>
</div>
When I implement the code like this:
import { VueDraggableNext } from "vue-draggable-next";
components: {
draggable: VueDraggableNext
},
with
list: [
{ name: 'John', id: 1 }, { name: 'Joao', id: 2 }, { name: 'Jean', id: 3 }, { name: 'Gerard', id: 4 }, ],
and im the template I already tried:
<draggable class="dragArea list-group w-full" :list="list" @change="log"> <div class="list-group-item bg-gray-300 m-1 p-3 rounded-md text-center" v-for="element in list" :key="element.name" > {{ element.name }} </div> </draggable>
and this:
<draggable
:list="list"
:disabled="!enabled"
item-key="name"
class="list-group"
ghost-class="ghost"
:move="checkMove"
@start="dragging = true"
@end="dragging = false"
>
<template #item="{ element }">
<div class="list-group-item" :class="{ 'not-draggable': !enabled }">
{{ element.name }}
</div>
</template>
</draggable>
In the case where I use
<template #item="{ element }">
Nothing is showing, and in the other case, nothing is draggable.
The component is loaded, I can see it with the Vue extension for Chrome:
Does anyone have any idea why it is not working?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有正确地导入VUE拖动软件包。
这样做:
然后这样使用它:
希望它有效!!
You did not correctly import the vue draggable package.
Do it like this:
and after that use it like this:
Hope it works!!
编辑:这是一个示例,为什么您应该发布整个代码...
因此,在尝试不同的几个小时后,我遇到了我添加的组件:数据()。
现在,它可以正常工作:
这就是我正在做的事情:
希望这对某人有帮助...
Edit: This is an example, why you should post your whole code...
So, after hours and hours of trying different things, I came across that I have added, components: to the data().
Now, it works fine with this:
and this is what I was doing:
Hope this helps someone in the future...