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>
相关推荐
Amumu121388 小时前
React 前端请求
前端·react.js·okhttp
内存不泄露8 小时前
基于Spring Boot和Vue的企业办公自动化系统设计与实现
java·vue.js·spring boot·intellij-idea
北辰alk8 小时前
toRef 和 toRefs 详解及应用
vue.js
北辰alk8 小时前
什么是 Vue 3 中的 `defineEmits`?
vue.js
3824278278 小时前
JS表单提交:submit事件的关键技巧与注意事项
前端·javascript·okhttp
于是我说8 小时前
Vue3 的 CompositionAPI 相较于 OptionsAPI,主要优势和适用场景有哪些
vue.js
Kagol9 小时前
深入浅出 TinyEditor 富文本编辑器系列2:快速开始
前端·typescript·开源
VX:Fegn08959 小时前
计算机毕业设计|基于springboot + vue智慧养老院管理系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
interception9 小时前
js逆向之京东原型链补环境h5st
javascript·爬虫·网络爬虫
木土雨成小小测试员9 小时前
Python测试开发之前端二
javascript·python·jquery