栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

Vue使用vue-draggable 插件在不同列表之间拖拽功能

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Vue使用vue-draggable 插件在不同列表之间拖拽功能

今天分享一个vue项目中在不同列表拖拽设置选项的功能,这个功能也是在做项目中遇到的,先说下这个功能的要点(参考下图),有2个列表,左侧列表展示已选,右侧列表展示未选,通过拖拽进行设置,已选的选项不能超过4个,超过的话自动将拖拽之前的最后一项清除到右侧,且如果从已选往未选里拖的时候,右侧显示垃圾桶的提示(如图)。

拖拽功能图片:

垃圾桶显示图:

首先讲讲vue-draggable的使用

安装vue-draggable:

npm install vuedraggable

在使用插件的组件内引入vue-draggable并注册组件:

import draggable from "vuedraggable"

components: {
 draggable
}

然后在我们需要拖拽的列表中使用:


 
  • {{item.name}}
  • 下面是拖拽功能组件的完整代码:

    
    
    
    
    body, ul, dl, dt, dd, li, h1, h3{
     margin: 0;
     padding: 0;
    }
    ul, ol, li {
     list-style: none;
    }
    .theme-setting {
     /deep/.el-dialog {
     height: 476px;
     border-radius: 6px;
     .el-dialog__header {
      height: 55px;
      line-height: 56px;
      padding: 0;
      border-bottom: 1px solid rgba(13,20,30, 0.1);
      .el-dialog__title {
      height:21px;
      font-size:16px;
      font-family:MicrosoftYaHei-Bold,MicrosoftYaHei;
      font-weight:bold;
      color:rgba(13,20,30,1);
      line-height:21px;
      }
      .el-dialog__headerbtn {
      margin-top: -4px;
      }
     }
     .el-dialog__body {
      position: relative;
      display: flex;
      height: 331px;
      padding: 0;
      border-bottom: 1px solid rgba(13,20,30, 0.1);
      .theme-left {
      width: 218px;
      margin-left: 24px;
      border-right: 1px solid rgba(13,20,30, 0.1);
      .theme-title {
       display: flex;
       margin-top: 24px;
       .title {
       height:19px;
       margin-right: 4px;
       font-size:14px;
       font-family:MicrosoftYaHei-Bold,MicrosoftYaHei;
       font-weight:bold;
       color:rgba(13,20,30,1);
       line-height:19px;
       }
       .des {
       height:16px;
       font-size:12px;
       font-family:MicrosoftYaHei;
       color:rgba(13,20,30,0.6);
       line-height:19px;
       }
      }
      .selected-list {
       height: 240px;
       margin-top: 24px;
       overflow: hidden;
       .selected-theme {
       width:160px;
       height:48px;
       line-height:48px;
       text-align: center;
       margin-bottom: 16px;
       cursor: pointer;
       background:linear-gradient(180deg,rgba(43,46,83,1) 0%,rgba(108,116,150,1) 100%);
       border-radius:6px;
       font-size:14px;
       font-family:MicrosoftYaHei;
       color:rgba(255,255,255,1);
       }
      }
      }
      .theme-right {
      padding: 0 24px;
      .theme-right-title {
       padding-top: 24px;
       height:19px;
       font-size:14px;
       font-family:MicrosoftYaHei-Bold,MicrosoftYaHei;
       font-weight:bold;
       color:rgba(13,20,30,0.4);
       line-height:19px;
      }
      .theme-right-list {
       width: 357px;
       height: 240px;
       overflow: scroll;
       margin-top: 24px;
       .theme-right-item {
       width: 160px;
       height:48px;
       line-height:48px;
       float: left;
       margin-right: 16px;
       margin-bottom: 16px;
       background:rgba(247,248,252,1);
       border-radius:6px;
       font-size:14px;
       font-family:MicrosoftYaHei;
       color:rgba(13,20,30,0.4);
       text-align: center;
       cursor: pointer;
       }
      }
      .theme-right-list::before, .theme-right-list::after {
       content: "";
       display: table;
      }
      .theme-right-list::after {
       clear: both;
      }
      }
      .drag-drop-del {
      position: absolute;
      right: 1px;
      top: 0;
      width: 404px;
      height: 331px;
      display: flex;
      justify-content: center;
      align-items: center;
      background-image: url('../../src/assets/imgs/drapDrop/drag_drop.png');
      img {
       width: 96px;
       height: 96px;
      }
      }
     }
     .el-dialog__footer {
      height: 88px;
      padding: 24px 24px 0;
      .dialog-footer {
      .el-button+.el-button {
       margin-left: 16px;
      }
      }
     }
     }
    }
    

    总结

    到此这篇关于Vue使用vue-draggable 插件在不同列表之间拖拽功能的文章就介绍到这了,更多相关vue vue-draggable 插件 拖拽内容请搜索考高分网以前的文章或继续浏览下面的相关文章希望大家以后多多支持考高分网!

    转载请注明:文章转载自 www.mshxw.com
    本文地址:https://www.mshxw.com/it/70981.html
    我们一直用心在做
    关于我们 文章归档 网站地图 联系我们

    版权所有 (c)2021-2022 MSHXW.COM

    ICP备案号:晋ICP备2021003244-6号