• el-upload 修改默认样式


    官网默认样式:

     目标样式:

    1、template:

    <div class="adds_item">
        <div class="adds_item_txt">软件图片:</div>
        <div class="adds_item_info">
            <el-upload
                class="upload-demo"
                :class="{hide:hideUpload}"
                action=""
                :auto-upload="false"
                :show-file-list='true'
                :file-list="certificates"
                :on-preview="showimg"
                :on-change="handlePictureCardPreview"
                :on-exceed="handleExceed"
                :on-remove="handleRemove"
                :limit="1"
                accept=".jpg,.jpeg,.png,.JPG,.JPEG"
                list-type="picture-card">
                <i class="el-icon-picture-outline"></i>
                <el-button class="upload_btn" size="small" type="primary">上传图片</el-button>
            </el-upload>
            <el-dialog :visible.sync="dialogVisibleImg">
                <img width="100%" :src="showimgs" alt="">
            </el-dialog>
        </div>
    </div>

    2、data:

    hideUpload: false,
    limitCount: 1,
    software_Img: '',//软件图片
    certificates: [], // 软件图片回显
    dialogVisibleImg: false,//软件图片是否显示大图
    showimgs: '',//软件图片大图

    3、methods:

    // 软件上传-软件图片选中
    handlePictureCardPreview(file, fileList) {
        this.softwareChange = true;
        const isLt5M = file.size <  1024 * 1024;
        let extension = file.name.substring(file.name.lastIndexOf('.') + 1);
        if (!isLt5M) {
            this.$message.error('上传图片大小不能超过 1M!');
            fileList.splice(-1,1);
            return false;
        }
        if(extension !== 'jpg' && extension !== 'jpeg' && extension !== 'png' && extension !== 'JPG' && extension !== 'JPEG') {
            this.$message.error('只能上传.jpg,.jpeg,.png,.JPG,.JPEG的文件!');
            fileList.splice(-1,1);
            return false;
        }
        const readers = new FileReader();
        readers.readAsDataURL(file.raw);
        readers.onload = () => {
            this.software_Img = readers.result;
        }
        this.hideUpload = fileList.length >= this.limitCount;
    },
    // 软件上传-软件图片限制上传
    handleExceed(files, fileList) {
        this.$message.warning(`当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`);
    },
    // 软件上传-软件图片删除
    handleRemove(file, fileList) {
        var that = this;
        fileList.forEach((item, index) => {
            that.certificate.push(item.url);
        })
        this.software_Img = '';
        this.softwareChange = false;
        this.hideUpload = fileList.length >= this.limitCount;
    },
    // 软件上传-软件图片显示
    showimg(file) {
        this.showimgs = file.url;
        this.dialogVisibleImg = true;
    },

    4、css:

    //上传按钮
    .upload-demo /deep/ .el-upload--picture-card .upload_btn{ background: #fff; color: #3C56C6; border: none; border-radius: 0; position: absolute; bottom: -5px; right: -90px; pointer-events: auto; //按钮穿透点击 text-decoration: underline; } .upload-demo /deep/ .el-upload--picture-card, .upload-demo /deep/ .el-upload-list--picture-card .el-upload-list__item{ line-height: 100px; font-size: 12px; height: 100px; 100px; position: relative; background: #F8F8F8; border: 1px solid #d2d2d2; border-radius: 0; } .upload-demo /deep/ .el-upload--picture-card{ pointer-events: none; //禁止点击 }
  • 相关阅读:
    Java核心技术 卷一 笔记四 库类的直接使用
    Java核心技术 卷一 笔记三 大数值及数组
    Java核心技术 卷一 笔记2 字符串的复制
    Java核心技术 卷一 笔记1
    修改css 样式后, hover事件 不生效
    修改 element ui input 输入框 样式不生效问题
    css3 计算属性
    Vue3 改动系列
    浏览器实现,向下滑动 鼠标滚轮,页面横向移动
    linux ceont0s7 vue 打包压缩图片 一直报错
  • 原文地址:https://www.cnblogs.com/moguzi12345/p/14648304.html
Copyright © 2020-2023  润新知