vue图片截取插件

在这里插入图片描述

  <VueCropper
                v-if="isCropper"
                ref="cropper"
                :img="option.img"
                :outputSize="option.outputSize"
                :outputType="option.outputType"
                :info="true"
                :full="option.full"
                :canMove="option.canMove"
                :canMoveBox="option.canMoveBox"
                :original="option.original"
                :autoCrop="option.autoCrop"
                :autoCropWidth="option.autoCropWidth"
                :autoCropHeight="option.autoCropHeight"
                :fixed="true"
                :fixedBox="option.fixedBox"
                :fixedNumber="fixedNumber"
                :infoTrue="option.infoTrue"
                :centerBox="option.centerBox"
                :maxImgSize="10000"
                :canScale="option.canScale"
              ></VueCropper>

js

import { VueCropper } from "vue-cropper";

  async confirm() {
      // 执行裁剪操作
      this.$refs.cropper.getCropBlob(async (data) => {
        const blobObj = new Blob([data], { type: "image/png" });
        const fileObj = this.blobToFile(blobObj, "example.png");
        let img = window.URL.createObjectURL(data);  
          // 将file数据上传到服务器
          const res = await addUploadImg(fileObj);
          if (res.code == 0) {
            this.audioSource = res.data.imgUrl;
            this.option.oldFileUrl = res.data.fileUrl;
            this.option.img = res.data.coverImg;
            this.isCropper = false
          }
      });
    },


  blobToFile(theBlob, fileName) {
      // 定义文件类型
      const fileType = theBlob.type;
      // 根据 Blob 和文件名 创建一个 File 对象
      const file = new File([theBlob], fileName, { type: fileType });
      // 返回 File
      return file;
    },

data

  option: {
        img: "",
        outputSize: 1, //剪切后的图片质量(0.1-1)
        full: false, //输出原图比例截图 props名full
        outputType: "png",
        canMove: true,
        original: false,
        canMoveBox: true,
        autoCrop: true,
        fixed: true,
        fixedBox: false,
        // fixedNumber: [1, 1],
        autoCropWidth: 150,
        autoCropHeight: 150,
        infoTrue: false,
        centerBox: true,
      },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值