2.0.0 • Published 3 years ago

mg-vue-cropper v2.0.0

Weekly downloads
70
License
MIT
Repository
-
Last release
3 years ago

mg-vue-cropper

Installation

$ npm i --save mg-vue-cropper

Useage

// 1.Global Registration (in main.js)
import MgCropper from 'mg-vue-cropper'
Vue.use(MgCropper)

OR

// 2.Local Registration (in xxx.vue)
import { cropper } from 'mg-vue-cropper'

components: {
    mgCropper: cropper
}

<!-- Cut Mode -->
<mg-cropper
    ref="mgCropper"
    :width="770"
    :height="300"
    color-primary="#6676FF"
    color-bg="rgba(0, 0, 0, 0.8)"
    :original-url="originalUrl"
    :equi-ratio="false"
    :min-cut-width="16"
    :min-cut-height="16"
    :init-cut-width="16"
    :init-cut-height="16"
    :init-cut-left="0"
    :init-cut-top="0"
    :rotate-visible="true"
    :preview-visible="true"
    preview-height="42%"
    @img-onload="imgOnloadHandle"
    @img-onerror="imgOnerrorHandle" />

<!-- Chartlet Mode -->
<mg-cropper
    ref="mgCropper"
    :width="770"
    :height="300"
    color-primary="#6676FF"
    color-bg="rgba(0, 0, 0, 0.8)"
    :original-url="originalUrl"
    :rotate-visible="true"
    :chartlet-on="true"
    :chartlet-list="chartletList"
    :current-chartlet="currentChartlet"
    :chartlet-init-left="10"
    :chartlet-init-top="10"
    @img-onload="imgOnloadHandle"
    @img-onerror="imgOnerrorHandle">
    <!-- Diy Component or DOM -->
    <chartlet-list
        :chartlet-list="chartletList"
        :current-chartlet="currentChartlet"
        @chose-chartlet="choseChartletHandle" />
</mg-cropper>

Attributes

参数说明类型是否必传默认值
widthmg-cropper容器宽Number770
heightmg-cropper容器高Number300
color-primary主题色String#6676FF
color-bg画布背景色Stringrgba(0, 0, 0, 0.8)
original-url需要裁剪的图片原始URLString
equi-ratio是否开启等比缩放,默认关闭Booleanfalse
min-cut-width裁剪框的最小宽(相对于原图)Number16
min-cut-height裁剪框的最小高(相对于原图)Number16
init-cut-width裁剪框的初始宽(相对于原图)Number16
init-cut-height裁剪框的初始高(相对于原图)Number16
init-cut-left裁剪框的初始位置left(相对于原图)Number0
init-cut-top裁剪框的初始位置top(相对于原图)Number0
rotate-visible是否显示旋转按钮(默认隐藏)Booleanfalse
preview-visible是否显示预览框(默认隐藏)Booleanfalse
preview-height预览框的高度String/Number42%
chartlet-on是否开启贴图功能(默认不开启),贴图功能与裁剪功能互斥Booleanfalse
chartlet-list贴图列表 { name: '贴图名(请确保有值且唯一)', url: '贴图地址' }Array[]
current-chartlet选中的贴图对象 { name: '贴图名(请确保有值且唯一)', url: '贴图地址' }Object{ name: '', url: '' }
chartlet-init-left贴图的初始位置left(相对于原图)Number10
chartlet-init-top贴图的初始位置top(相对于原图)Number10

Methods

方法名说明参数返回值
saveImg保存裁剪图片(会生成blob和blobUrl用于上传和显示)。参数说明,cutPos : 裁剪区域四个角坐标; cutSize: 裁剪区域尺寸; naturalSize: 原始图片大小; hasChartlet: 是否添加了贴图Promise { blob, blobUrl, cutPos, cutSize, naturalSize, hasChartlet }
downloadImg下载裁剪图片fileName: 下载文件名(不传默认使用时间戳)
setCutBoxSize手动设置裁剪框的尺寸(相对于原图)width(不小于16px), height(不小于16px)
setCutBoxPos手动设置裁剪框的位置(相对于原图)left, top
setChartletPos手动设置贴图的位置(相对于原图)left, top

Slot

name说明
default插槽,裁剪框右侧区的内容

Events

事件名说明回调参数
img-onload图片加载完成event
img-onerror图片加载失败event
img-onabort图像加载被中断event

Npm

mg-vue-cropper

2.0.0

3 years ago

2.0.0-beta.2

3 years ago

2.0.0-beta.1

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.9.1

4 years ago

0.9.0

4 years ago

0.8.0

4 years ago

0.7.0

4 years ago

0.5.0

4 years ago

0.6.0

4 years ago

0.3.0

4 years ago

0.4.0

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago