首页 > 其他分享 >vue中el-upload结合vuedraggable实现图片的上传、排序、删除以及预览等功能_element upload

vue中el-upload结合vuedraggable实现图片的上传、排序、删除以及预览等功能_element upload

时间:2023-11-15 21:11:27浏览次数:35  
标签:el vue console log url upload fileList file

<template>
    <div>
        <ul class="el-upload-list el-upload-list--picture-card" style="display:flex;">
            <div>
                <!-- start:拖拽开始 end:拖拽结束  imageLists:需要展示图片的数组-->
                <draggable class="el-upload-list el-upload-list--picture-card" v-model="imageLists" @start="onStart"
                    @end="onEnd">

                    <div class="el-upload-list__item is-success" v-for="(item, index) in imageLists" :key="item + index">
                        <li>
                            <div class="content1">
                                <img :src="item.url" class="el-upload-list__item is-success" />
                                <span class="el-upload-list__item-actions">
                                    <!-- 删除图片 -->
                                    <span class="remove">
                                        <i class="el-icon-delete" @click="delImg(index)"></i>
                                    </span>
                                    <!-- 放大图片 -->
                                    <span class="remove">
                                        <i class="el-icon-circle-plus-outline"
                                            @click="handlePictureCardPreview(item.url)"></i>
                                    </span>
                                </span>
                            </div>
                        </li>
                    </div>
                </draggable>
            </div>
            <el-upload action="#" list-type="picture-card" :auto-upload="false" :show-file-list="false" :on-change="handleChange" multiple>
                <i slot="default" class="el-icon-plus"></i>
            </el-upload>

            <!-- 图片回显预览 -->
            <el-dialog title="图片预览" :visible.sync="dialogVisible" width="50%" height="80%" append-to-body>
                <img :src="dialogImageUrl" alt="" style="width:100%;height:100%" />
            </el-dialog>
        </ul>
    </div>
</template>

<script>
import draggable from "vuedraggable";
export default {
    components: {
        draggable,
    },
    data() {
        return {
            imageLists: [   
            ],
            drag: false,
            dialogImageUrl: "",
            dialogVisible: false,
            resourcesUrl: process.env.VUE_APP_RESOURCES_URL,
            
        };
    },
    components: {
        draggable,
    },

    methods: {
        handleChange(file) {
            debugger;
            var obj = {
                  url: file.url,
                  name: file.name,
              }

            this.imageLists.push(obj);
        },
        //开始拖拽事件
        onStart() {
        },
        //拖拽结束事件
        onEnd(e) {
            console.log(e); // 这里将会有调整前后的 index 及其他可能需要传递给接口的信息

        },
        beforeAvatarUpload(file) {
            console.log(file);
        },
        handleRemove(file, fileList) {
            console.log(file, fileList);

        },
        delImg(index) {
            this.imageLists.splice(index, 1)
        },
        handleUploadSuccess(response, file, fileList) {
            console.log(response, file, fileList);
        },
        handlePictureCardPreview(url) {
            this.dialogImageUrl = url;
            this.dialogVisible = true;
        },

    },
};
</script>
<style lang="sass" scoped></style>

 

标签:el,vue,console,log,url,upload,fileList,file
From: https://www.cnblogs.com/cxxjohnson/p/17834803.html

相关文章

  • element plus -- el-table 中分页选中回显
    需求:切换分页或者根据筛选条件过滤后选中项依然保持选中状态代码:<el-rowclass="pro-list-container"><el-table:data="productAttrs"ref="multipleTable"class="pro-table":header-cell-style="{backgrou......
  • Excel文件导入
    前端<divclass="panel-body"><spanclass="glyphiconglyphicon-th-list"aria-hidden="true"></span>批量上传</div>后端defdepart_multi(request): '''导入Excel文件''......
  • 【开源】基于Vue.js的高校实验室管理系统
    一、摘要1.1项目介绍基于JAVA+Vue+SpringBoot+MySQL的高校实验室管理系统包含实验室类型模块、实验室档案模块、实验模块、实验设备模块、实验订单模块,还包含系统自带的用户管理、部门管理、角色管理、菜单管理、日志管理、数据字典管理、文件管理、图表展示等基础模块,高校实验室......
  • 【开源】基于Vue.js的衣物搭配系统的设计和实现
    一、摘要1.1项目介绍基于Vue+SpringBoot+MySQL的衣物搭配系统,包含衣物档案模块、衣物搭配模块、衣物收藏模块,还包含系统自带的用户管理、部门管理、角色管理、菜单管理、日志管理、数据字典管理、文件管理、图表展示等基础模块,衣物搭配管理系统基于角色的访问控制,给普通用户、衣物......
  • 无涯教程-Dart - Inserting Elements into a List函数
    可变列表可以在运行时动态增长,List.add()函数将指定的值附加到List的末尾,并返回修改后的List对象,如下所示。voidmain(){Listl=[1,2,3];l.add(12);print(l);}它将产生以下输出-[1,2,3,12]List.addAll()函数接受多个用逗号分隔的值,并将它们附加到列......
  • 免费IDEA插件分享:Apipost-Helper
    今天给大家推荐一款IDEA插件:Apipost-Helper-2.0,写完代码IDEA内一键生成API文档,无需安装、打开任何其他软件;写完代码IDEA内一键调试,无需安装、打开任何其他软件;生成API目录树,双击即可快速定位API定义的代码…非常好用!而且完全免费!在IDEA编辑器插件中心输入Apipost搜索安装:Apipost-......
  • 碾压Fast Request!IDEA插件推荐:Apipost-Helper
    IDEA是一款功能强大的集成开发环境(IDE),它可以帮助开发人员更加高效地编写、调试和部署软件应用程序。我们在编写完接口代码后需要进行接口调试等操作,一般需要打开额外的调试工具,而今天给大家介绍一款IDEA插件:Apipost-Helper-2.0。代码写完直接编辑器内调试、还支持生成接口文档、接......
  • 免费IDEA插件分享:Apipost-Helper
    今天给大家推荐一款IDEA插件:Apipost-Helper-2.0,写完代码IDEA内一键生成API文档,无需安装、打开任何其他软件;写完代码IDEA内一键调试,无需安装、打开任何其他软件;生成API目录树,双击即可快速定位API定义的代码…非常好用!而且完全免费!在IDEA编辑器插件中心输入Apipost搜索安装:Apipost......
  • 【Vue】组件传值的六种方法
    Vue组件之间的通信大概归类为:父子组件通信:props;ref;$attrs/$listeners;$parent/$children兄弟组件通信:eventBus;vuex跨级通信:eventBus;Vuex;$attrs/$listeners一、props/$emit1.父组件向子组件传值通过props传值。父组件的代码:<template><divclass="secti......
  • 碾压Fast Request!IDEA插件推荐:Apipost-Helper
    IDEA是一款功能强大的集成开发环境(IDE),它可以帮助开发人员更加高效地编写、调试和部署软件应用程序。我们在编写完接口代码后需要进行接口调试等操作,一般需要打开额外的调试工具,而今天给大家介绍一款IDEA插件:Apipost-Helper-2.0。代码写完直接编辑器内调试、还支持生成接口文档、接......