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>
相关推荐
weixin_4692738129 分钟前
.md文件是什么?.md如何打开?
前端·编辑器
不好听61335 分钟前
Web Worker:浏览器给 JS 开的后台子线程
前端·浏览器
用户241714014186037 分钟前
一个 Tapas 菜单 App,逼我啃下了前端存储和 this 绑定两座大山
javascript
计算机魔术师40 分钟前
数据分析还在靠人跑 SQL?AI 智能体已经把效率拉到 63 倍
前端
瑞码空间1 小时前
Routing & API:前后端协作的本质与实现
前端·后端·接口·路由
不好听6131 小时前
React 的 useRef vs useState:响应式与非响应式的分界线
前端·react.js
我真是泰库辣1 小时前
用TraeWork制作应用 —— 从 0 到 1 · 手把手搭建 opencode 网页对话网关
前端·后端
xiaominlaopodaren1 小时前
three.js地图数学基础(二):Web Mercator
javascript·gis·three.js
mONESY1 小时前
深入理解 React useRef:从 DOM 操作到持久化存值的完整指南
javascript
谷哥的小弟1 小时前
TypeScript接口
javascript·typescript