上传按钮upload上传组件

1.上传组件

components>upload>index.vue

<template>
  <div>
    <el-upload
      :action="$uploadAction()"
      accept="image/jpeg,image/jpg,image/png"
      list-type="picture-card"
      :before-upload="handleBeforeUpload"
      :on-success="handleSuccess"
      :limit="limit"
      :show-file-list="false"
    >
      <el-image v-if="src" :src="src" class="upload-image"></el-image>
      <i slot="default" class="el-icon-plus" v-else></i>
      <span slot="tip" class="el-upload__tip note" v-if="showTip">
        {{ tip }}
      </span>
    </el-upload>
  </div>
</template>

<script>
export default {
  name: "Upload",
  data() {
    return {};
  },
  props: {
    src: String,
    limitSize: {
      type: Number,
      default: 200,
    },
    limit: {
      type: Number,
      default: 2,
    },
    showTip: {
      type: Boolean,
      default: true,
    },
    tip: {
      type: String,
      default:
        "* 注:图片尺寸为:401*401px,图片格式为jpg,jpeg,png,大小不建议超过200k",
    },
  },
  computed: {},
  methods: {
    handleBeforeUpload(file) {
      if (file.size / 1024 > this.limitSize) {
        this.$message.error(`上传机台图片大小不能超过 ${this.limitSize} K!`);
        return false;
      }
      return true;
    },

    handleSuccess(res) {
      this.$emit("update:src", res.data);
    },
  },
};
</script>

<style lang="scss" scoped>
.upload-image {
  width: 100%;
  height: 100%;
  .el-image__inner {
    background-size: cover;
  }
}
::v-deep.el-upload__tip{
  position: absolute;
  bottom: 0;
  margin-left: 10px;
}
</style>

2.使用组件

(题外话,这个精准到每一行的提交记录提示是安装了GitLens拓展)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值