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

html 复制代码
<template>
   <!-- 省略其他配置 -->
   <el-upload ref="upload" :file-list.sync="fileList"></el-upload>
 </template>
javascript 复制代码
 <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>
相关推荐
剪刀石头布啊6 小时前
vue-react为何要虚拟dom
前端
剪刀石头布啊6 小时前
ahooks常用的一些库,我们使用一下
前端
剪刀石头布啊6 小时前
从git更新本地提交记录到更新已经推送到远端记录
前端
云浪7 小时前
Go 并发实战:从零实现一个高并发安全的任务调度器
javascript·后端·go
Flynt8 小时前
axios 被投毒半年后,我把 npm 的"安全防线"实测了一遍:最信任的 SHA512 是安慰剂
前端·npm·node.js
excel9 小时前
Base62 和 Base64 有什么区别?
前端
风骏时光牛马10 小时前
大模型底层架构与AI源码深度剖析
前端
掘金挖土11 小时前
前端手摸手跑路之 AI 应用开发(九)
前端·后端
中文呀13 小时前
三维 GIS 离线缓存实战:逆向 CesiumOfflineCache,并亲手为它补上"自动更新"能力
前端