vue中拖拽组件使用------vuedraggable

1、安装

cnpm i -S vuedraggable

2、使用

import draggable from "vuedraggable";

3、代码 

<template>
  <section class="main">
    <div class="crumbs">
      <el-breadcrumb separator="/"></el-breadcrumb>
    </div>
    <div class="container">
      <div class="drag-box">
        <el-row>
          <el-col :span="24">
            <div class="drag-box-item">
              <div class="item-title">已选菜单</div>
              <draggable v-model="bytesUsedMenu" @remove="removeHandle" :options="dragOptions">
                <transition-group tag="div" id="已选菜单" class="item-ul">
                  <div
                    v-for="item in bytesUsedMenu"
                    class="drag-list"
                    :key="item.id"
                    style="min-width: 40px;float: left;"
                  >{{item.content}}</div>
                  <div @click="addMenu" key="55" class="drag-list notMove">添加新菜单</div>
                </transition-group>
              </draggable>
            </div>
          </el-col>
        </el-row>
      </div>
      <br />
      <div class="drag-box">
        <el-row>
          <el-col :span="24">
            <div class="drag-box-item">
              <div class="item-title">未选菜单</div>
              <draggable v-model="unusedMenu" @remove="removeHandle" :options="dragOptions">
                <transition-group tag="div" id="未选菜单" class="item-ul">
                  <div
                    v-for="item in unusedMenu"
                    class="drag-list"
                    :key="item.id"
                    style="min-width: 40px;float: left;"
                  >{{item.content}}</div>
                </transition-group>
              </draggable>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
  </section>
</template>

<script>
import draggable from "vuedraggable";
export default {
  name: "draglist",
  data() {
    return {
      dragOptions: {
        animation: 120,
        scroll: true,
        group: "sortlist",
        ghostClass: "ghost-style",
        filter: ".notMove"
      },
      bytesUsedMenu: [
        {
          id: 1,
          content: "首页"
        },
        {
          id: 2,
          content: "简介"
        },
        {
          id: 3,
          content: "研究内容"
        },
        {
          id: 4,
          content: "团队合作"
        },
        {
          id: 5,
          content: "新闻动态"
        },
        {
          id: 6,
          content: "团队出行"
        }
      ],
      unusedMenu: []
    };
  },
  components: {
    draggable
  },
  methods: {
    addMenu() {
      this.bytesUsedMenu.push({
        id: this.bytesUsedMenu.length + 1 + "",
        content: "自定义菜单" + this.bytesUsedMenu.length + 1
      });
    },
    removeHandle(event) {
      console.log(this.bytesUsedMenu);
      console.log(this.unusedMenu);
      console.log(event);
      this.$message.success(`从 ${event.from.id} 移动到 ${event.to.id} `);
    }
  }
};
</script>

<style scoped>
.drag-box {
  display: flex;
  user-select: none;
}
.drag-box-item {
  width: 900px;
  min-height: 105px;
  flex: 1;
  /* max-width: 600px; */
  min-width: 400px;
  background-color: #eff1f5;
  margin-right: 16px;
  border-radius: 6px;
  border: 1px #e1e4e8 solid;
}
.item-title {
  padding: 8px 8px 8px 12px;
  font-size: 14px;
  line-height: 1.5;
  color: #24292e;
  font-weight: 600;
}
.item-ul {
  padding: 0 8px 8px;
  /* height: 500px; */
  overflow-y: scroll;
}
.item-ul::-webkit-scrollbar {
  width: 0;
}
.drag-list {
  border: 1px #e1e4e8 solid;
  padding: 10px;
  margin: 5px 0 10px;
  list-style: none;
  background-color: #fff;
  border-radius: 6px;
  cursor: pointer;
  -webkit-transition: border 0.3s ease-in;
  transition: border 0.3s ease-in;
}
.drag-list:hover {
  border: 1px solid #20a0ff;
}
.drag-title {
  font-weight: 400;
  line-height: 25px;
  margin: 10px 0;
  font-size: 22px;
  color: #1f2f3d;
}
.ghost-style {
  display: block;
  color: transparent;
  border-style: dashed;
}
.notMove {
  color: #ffff;
  background-color: #409eff;
  min-width: 40px;
  float: left;
}
</style>

4、效果

 来源:以前收集的git上的开源项目 ,找不到地址了....

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值