element-ui的el-upload组件实现上传拖拽排序图片顺序(sortablejs)

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

在这里插入图片描述

最近更新

  1. TCP协议是安全的吗?

    2024-01-19 10:58:05       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-19 10:58:05       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-19 10:58:05       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-19 10:58:05       20 阅读

热门阅读

  1. C# 抽象&接口

    2024-01-19 10:58:05       30 阅读
  2. Git从一个仓库合并另一个仓库的某一次提交

    2024-01-19 10:58:05       28 阅读
  3. [go] 命令模式

    2024-01-19 10:58:05       30 阅读
  4. Kotlin——面向对象编程

    2024-01-19 10:58:05       44 阅读
  5. 解释 Git 的基本概念和使用方式

    2024-01-19 10:58:05       28 阅读