请问是否有这样的vue或者前端三方组件(可以添加块,然后进行拖拽)?

请问是否有这样的vue或者前端三方组件?

可以添加块,然后进行拖拽:

image.png

阅读 693
avatarAI BotBETA

以下是符合你需求的前端组件推荐(支持动态添加模块 + 自由拖拽):


⭐ 推荐方案:Vue.Draggable + 自定义布局

组件库: Vue.Draggable (基于 Sortable.js)
特点:

  • 支持动态添加/删除块
  • 跨容器拖拽 + 动画效果
  • 兼容 Vue 2/3
  • 示例代码:

    <template>
    <draggable v-model="blocks" @end="onDragEnd">
      <div v-for="block in blocks" :key="block.id" class="drag-block">
        {{ block.content }}
        <button @click="removeBlock(block.id)">删除</button>
      </div>
    </draggable>
    <button @click="addBlock">添加新块</button>
    </template>
    
    <script>
    import draggable from "vuedraggable";
    export default {
    components: { draggable },
    data() {
      return {
        blocks: [{ id: 1, content: "模块1" }]
      };
    },
    methods: {
      addBlock() {
        this.blocks.push({ 
          id: Date.now(), 
          content: `模块${this.blocks.length+1}` 
        });
      },
      removeBlock(id) {
        this.blocks = this.blocks.filter(block => block.id !== id);
      },
      onDragEnd(evt) {
        console.log("新顺序:", this.blocks);
      }
    }
    };
    </script>
    
    <style>
    .drag-block {
    padding: 20px;
    margin: 10px;
    background: #f0f0f0;
    cursor: move;
    }
    </style>

🖥️ 专业级解决方案

  1. Vue Grid Layout

  2. Interact.js + Vue 封装

  3. Dragula


📱 移动端优先


💡 使用建议

  1. 简单需求 → 直接使用 Vue.Draggable
  2. 需要网格布局 → Vue Grid Layout
  3. 需要自由画布式拖拽 → Interact.js
  4. 移动端H5 → Vant Drag
⚠️ 注意:所有方案都需要在拖拽结束时更新数据模型(如更新数组顺序),以实现状态持久化。
推荐问题