vue:使用【3.0】:拖拽数据

1、参考链接:vue.draggable中文文档 - itxst.com

2、想要实现的效果图:红框内容可以拖拽

3、安装

复制代码
yarn add vuedraggable@next
npm i -S vuedraggable@next

4、代码

javascript 复制代码
<template>
    <draggable
      :list="columns"
      ghost-class="ghost"
      chosen-class="chosenClass"
      animation="300"
      class="chooseMain"
    >
      <template #item="{ element, index }">
        <div class="card mr-10px">
          <div class="box mb-10px">
            <div class="left mr-10px">
              <div class="border"></div>
              <div class="txt">{{ element.label }}</div>
            </div>
            <div class="right">
              <Icon
                color="#409eff"
                class="mr-5px"
                icon="ep:delete"
                @click="handleRemove(element, index)"
              />
            </div>
          </div>
        </div>
      </template>
    </draggable>
</template>

<script lang="ts" setup>
import draggable from 'vuedraggable'
const list = [
  {label: '1', value: '测试数据1'},
  {label: '2', value: '测试数据2'}
  {label: '3', value: '测试数据3'}
  {label: '4', value: '测试数据4'}
]
</script>

<style lang="scss" scoped>
  .chooseMain {
    display: flex;
    flex-wrap: wrap;
    .card {
      display: flex;
      flex-basis: 19%;
      box-sizing: border-box;
    }
    .box {
      width: 100%;
      border: 1px solid #ccc;
      border-radius: 5px;
      display: flex;
      align-items: center;
      justify-content: space-around;
      padding: 0 5px;
      box-sizing: border-box;
      .left {
        display: flex;
        align-items: center;
        .border {
          height: 18px;
          width: 2px;
          border-left: 1px dotted #ccc;
          border-right: 1px dotted #ccc;
          display: flex;
          margin-right: 5px;
        }
        .txt {
          width: 130px;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          line-height: 28px;
        }
      }
      .right {
        width: 30px;
        display: flex;
        align-items: center;
      }
    }
  }
</style>
相关推荐
Csvn7 小时前
WASM
前端
修己xj9 小时前
我用 AI 给自己写了一个 Markdown 编辑器,然后把它开源了
前端
FRing039 小时前
vue2干货总结2(v-bind、v-for、v-model、指令修饰符、v-bind操作class和style)
开发语言·前端·vue.js·vue2
幸运小猿9 小时前
模拟慢上传-处理超时重试image 丢失线上问题
前端·javascript·html
moshuying11 小时前
网购能买Token了!
前端
h_654321011 小时前
echarts实现柱状图加一条横线
前端·echarts
风骏时光牛马11 小时前
生成一个后端标题,只需要一个标题,不需要其他的任何文本。
前端
子非鱼@Itfuture11 小时前
关于前后端联调中登录状态/登录信息失效?
java·前端
郭小李11 小时前
openFeign入门
java·开发语言·前端
馒头不想说话11 小时前
AI当运营,帮你省人力
前端