VUEJS 3可拖动问题

发布于 2025-01-22 09:03:43 字数 2278 浏览 0 评论 0原文

我正在使用“ 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:

enter image description here

Does anyone have any idea why it is not working?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

混吃等死 2025-01-29 09:03:43

您没有正确地导入VUE拖动软件包。
这样做:

import { VueDraggableNext } from "vue-draggable-next";

然后这样使用它:

<draggable :list="list">     
<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>

希望它有效!!

You did not correctly import the vue draggable package.
Do it like this:

import { VueDraggableNext } from "vue-draggable-next";

and after that use it like this:

<draggable :list="list">     
<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>

Hope it works!!

野の 2025-01-29 09:03:43

编辑:这是一个示例,为什么您应该发布整个代码...

因此,在尝试不同的几个小时后,我遇到了我添加的组件:数据()。
现在,它可以正常工作:

export default {
     components: {
    draggable: VueDraggableNext   },

这就是我正在做的事情:

data() {
    return {
      components: {
        draggable: VueDraggableNext
      },

希望这对某人有帮助...

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:

export default {
     components: {
    draggable: VueDraggableNext   },

and this is what I was doing:

data() {
    return {
      components: {
        draggable: VueDraggableNext
      },

Hope this helps someone in the future...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文