picture-card图片上传


<template>
  <div class="dialog-module">
        <el-upload
          :action="upload.url"
          list-type="picture-card"
          :headers="upload.headers"
          :class="{ hide: hideUpload }"
          :file-list="fileList"
          :limit="1"
          :auto-upload="true"
          :on-change="handleChange"
          :on-preview="handlePictureCardPreview"
          :disabled="isDetail"
          :on-remove="handleRemove"
          :on-success="handleSuccess"
        >
          <i slot="default" class="el-icon-plus"></i>
        </el-upload>
        <el-dialog :visible.sync="dialogVisible">
          <img width="100%" :src="dialogImageUrl" alt="" />
        </el-dialog>
  </div>
</template>

<script>
import { getToken } from "@/utils/auth";
export default {
  name: "DialogModule",
  data() {
    return {
         // 用户导入参数
      upload: {
        open: false,
        title: "",
        isUploading: false,
        updateSupport: 0,
        headers: { Authorization: "Bearer " + getToken() },
        url: process.env.VUE_APP_BASE_API + "/manager/tool/file/upload",
      },
      ///文件上传
      dialogImageUrl: "",
      dialogVisible: false,
      
      // hideUpload: false, // 控制选择框是否显示的开关
      fileList: [],
    };
  },
   computed: {
    hideUpload() {
      return this.form.logoUrl;
    },
  },
  methods: {
       handleSuccess(file, fileList) {
      console.log("success", file, fileList);
      this.form.logoUrl = file.data.fileUrl;
      // this.form.logoUrl.push(file.data.fileUrl);
    },
    handleChange(file, fileList) {
      console.log("change", fileList);
      // this.hideUpload = this.form.logoUrl.length > 0;
    },
    handleRemove(file, fileList) {
      console.log("remove", fileList);
      // 防止出场动画未结束,选择框提前出现
      setTimeout(() => {
        this.form.logoUrl = "";
        // this.hideUpload = this.form.logoUrl.length > 0;
      }, 1000);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
  },
};
</script>
 

<style>
.hide .el-upload--picture-card {
  display: none;
}
</style> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值