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>
相关推荐
贾公子5 分钟前
form组件的封装(element ui ) 简单版本
前端·javascript
贾公子6 分钟前
下拉框组件的封装(element ui )
前端·javascript
贾公子7 分钟前
ElementUI,在事件中传递自定义参数的两种方式
前端·javascript
贾公子8 分钟前
基于Vue3 + Typescript 封装 Element-Plus 组件
前端·javascript
vim怎么退出9 分钟前
43.验证二叉搜索树
前端·leetcode
记得开心一点嘛9 分钟前
使用Three.js搭建自己的3Dweb模型(从0到1无废话版本)
前端·javascript·three.js
这颗橘子不太甜QAQ9 分钟前
patch-package使用详解
前端·npm
贾公子9 分钟前
JavaScript 中的类型相等性比较 (宽松比较的小问题)
前端·javascript
我爱学习_zwj11 分钟前
Webpack模块打包工具
前端
贾公子12 分钟前
JavaScript 中那些不常见的 for 循环命名与高阶用法
前端·javascript