vue-cropper

1、安裝

npm install vue-cropper --save

2、引入

import cropperModel from '@/components/cropper/index'
components: {
  cropperModel
},

3、使用

<vue-cropper
      class="crop-box"
       ref="cropper"
        :img="options.img"
        :autoCrop="options.autoCrop"
        :fixedBox="options.fixedBox"
        :canMoveBox="options.canMoveBox"
        :autoCropWidth="options.autoCropWidth"
        :autoCropHeight="options.autoCropHeight"
        :centerBox="options.centerBox"
        :fixed="options.fixed"
        :fixedNumber="options.fixedNumber"
        :canMove="options.canMove"
        :canScale="options.canScale"
        :mode="options.mode"
 >
</vue-cropper>
data() {
  return {
    options: {
          img: this.imgSrc, // 原圖文件
          outputSize: 1, // 裁剪生成圖片的質(zhì)量
          outputType: 'png', // 裁剪生成圖片的格式 jpeg, png, webp
          info: true, // 裁剪框的大小信息
          canScale: true, // 圖片是否允許滾輪縮放
          autoCrop: true, // 是否默認(rèn)生成截圖框
          autoCropWidth: 500, // 默認(rèn)生成截圖框?qū)挾?          autoCropHeight: 500, // 默認(rèn)生成截圖框高度
          fixedBox: false, // 固定截圖框大小 不允許改變
          fixed: true, // 是否開啟截圖框?qū)捀吖潭ū壤?          fixedNumber: [1.5, 1], // 截圖框的寬高比例 [ 寬度 , 高度 ]
          canMove: true, // 上傳圖片是否可以移動(dòng)
          canMoveBox: true, // 截圖框能否拖動(dòng)
          original: false, // 上傳圖片按照原始比例渲染
          centerBox: true, // 截圖框是否被限制在圖片里面
          infoTrue: true, // true 為展示真實(shí)輸出圖片寬高 false 展示看到的截圖框?qū)捀?          full: true, // 是否輸出原圖比例的截圖
          enlarge: '1', // 圖片根據(jù)截圖框輸出比例倍數(shù)
          mode: 'contain' // 圖片默認(rèn)渲染方式 contain , cover, 100px, 100% auto
        },
  }
}

4、獲取裁剪好的圖片

this.$refs.cropper.getCropData(data => {
  console.log(data) //base64格式
})
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容