0.0.2 • Published 9 months ago

@moment-design/crop-image v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

裁剪图片组件

使用组件

安装依赖

npm install @moment-design/crop-image --save

使用组件

<template>
  <m-button type="primary" @click="refLAdvancedCropper.open()">
    触发裁剪弹窗
  </m-button>
  <CropImage
    ref="refLAdvancedCropper"
    img="https://preapiconsole.71360.com/w3/w475wn/20250116/967e3e343193b65f7108432f73e8e5a1.png"
    :others="{ stencilProps: { aspectRatio: 1 / 1 } }"
    @handle:ok="handleOk"
  ></CropImage>
  <div style="margin-top: 16px">Base64 length: {{ v1?.length }}</div>
  <div style="margin-top: 16px">Blob size: {{ v2?.size }}</div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import CropImage from '@moment-design/crop-image';

const v1 = ref();
const v2 = ref();

const refLAdvancedCropper = ref();
const handleOk = (canvas: any) => {
  if (canvas) {
    // base64
    const base64 = canvas.toDataURL();
    v1.value = base64;
    // blob
    canvas.toBlob((blob: any) => {
      v2.value = blob;
    });
    // do uload v1 or v2 ...
  }
};
</script>

API

Props

参数名描述类型默认值
img需要裁剪的图片地址string''
title裁剪弹窗的标题string'裁剪图片'
othersvue-advanced-cropper 官方配置(详见下链接)Object-

https://advanced-cropper.github.io/vue-advanced-cropper/introduction/getting-started.html

Events

事件名描述参数
handle:ok裁剪后的 canvas 对象,用于后续操作(canvas)

Expose

事件名描述参数
open主动触发打开弹窗-