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>
相关推荐
JS菌5 分钟前
Skills 动态加载系统:让 AI Agent 按需获取领域知识
前端·人工智能·后端
weedsfly7 分钟前
Sass 代码复用完全指南:从变量到模块化
前端
张拭心12 分钟前
Android 17 新特性:后台音频交互限制加强
android·前端
张拭心20 分钟前
Android 17 新特性:ProfilingManager 新触发器
android·前端
黄敬峰28 分钟前
从 XMLHttpRequest 到 JSON 模拟:打通前后端通信的任督二脉
javascript
weixin_4713830329 分钟前
Taro-03-页面生命周期
前端·javascript·taro
张拭心32 分钟前
Android 17 新特性:MessageQueue 无锁实现
android·前端
Asize35 分钟前
数组数据结构底层:从灵活到陷阱
前端·javascript·算法
十九画生35 分钟前
Ajax 入门:用 XHR 理解前后端异步请求
前端·javascript·后端