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>
相关推荐
Hilaku1 小时前
2027 制药行业 ERP 系统架构选型笔记:从 GMP 合规追溯到动态 MCP 接入
前端·javascript·程序员
掘金安东尼2 小时前
人工智能AI
前端
kyriewen2 小时前
AI 面试官筛前端简历,先出局的不是写代码慢的
前端·面试·程序员
时间的情敌3 小时前
Three.js 后处理辉光 Bloom、告警发光效果、管线流光、着色器流动管线(ShaderMaterial)
开发语言·javascript·three.js·着色器
BigTopOne3 小时前
10 引用与借用:& 和 &mut
前端
粥里有勺糖3 小时前
视野修炼-技术周刊第139期 | AI 不会让时间变多
前端·github·ai编程
ZJPRENO4 小时前
WorkBuddy 从零到一|混元4 Flash 实战手记-提醒小工具开发
前端
用户302822530685 小时前
AI 视频图片运镜为什么会抖?帧率拉高也救不了多次取整
前端·人工智能·typescript
前端码农人生5 小时前
前端转 Agent:真正要重写的不是接口层,是交互层
前端
AI2中文网5 小时前
App Inventor 做的表单怎么导出 PDF?WebViewer + JavaScript 在本地生成并保存 PDF 的完整示例
android·开发语言·javascript·pdf·鸿蒙·app inventor