el-upload组件实现上传拖拽排序图片顺序

之前是使用vuedraggable完成了一次上传拖拽的使用

但是在完成过程中css样式修改上传图标和拖拽区域不能很好的组合在一起

刷到了vuedraggable组件的js方法  sortablejs

Sortable.js是一款优秀的js拖拽库,支持ie9及以上版本ie浏览器和现代浏览器,也可以运行在移动触摸设备中。不依赖jQuery。支持 Meteor、AngularJS、React、Vue、Knockout框架和任何CSS库,如Bootstrap、Element UI。你可以用来拖拽div、table等元素。

相关文档推荐:
官方文档 https://github.com/SortableJS/Sortable
中文文档 https://www.itxst.com/sortablejs

需要进行npm安装 

$ npm install sortablejs --save
<template>
   <el-upload ref="ImageChang" :file-list.sync="photoList"></el-upload>
 </template>
 <script>
 import Sortable from 'sortablejs';
 export default {
   data() {
     return {
       photoList:[]
     };
   },
   mounted() {
     this.initDragSort();
   },
   methods: {
    // 支持拖拽排序
     initDragSort() {
       const el = this.$refs.ImageChang.$el.querySelectorAll('.el-upload-list')[0];
       Sortable.create(el, {
         onEnd: ({ oldIndex, newIndex }) => {
           // 交换位置
           const arr = this.photoList;
           const page = arr[oldIndex];
           arr.splice(oldIndex, 1);
           arr.splice(newIndex, 0, page);
         }
       });
     }
   }
 };
 </script>

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-23 05:16:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-23 05:16:02       101 阅读
  3. 在Django里面运行非项目文件

    2024-02-23 05:16:02       82 阅读
  4. Python语言-面向对象

    2024-02-23 05:16:02       91 阅读

热门阅读

  1. 深入探讨YUV图像处理:理论原理与OpenCV实践

    2024-02-23 05:16:02       39 阅读
  2. @Conditional注解

    2024-02-23 05:16:02       50 阅读
  3. OpenAI Sora文本生成视频注册教程

    2024-02-23 05:16:02       79 阅读
  4. layui-tab加载echarts宽度丢失

    2024-02-23 05:16:02       52 阅读
  5. IMAP4揭秘:实现高效、灵活的电子邮件管理

    2024-02-23 05:16:02       45 阅读
  6. 力扣刷题记录:46_全排列(中)

    2024-02-23 05:16:02       59 阅读
  7. 解决windows无法访问wsl下docker服务

    2024-02-23 05:16:02       49 阅读
  8. 力扣49.字母异位词分组

    2024-02-23 05:16:02       52 阅读
  9. winform布局

    2024-02-23 05:16:02       54 阅读
  10. Python基础20 面向对象(3)多态、封装、反射

    2024-02-23 05:16:02       51 阅读