国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

Vue圖片裁剪組件實(shí)例代碼

發(fā)布時(shí)間:2021-08-17 12:16 來(lái)源: 閱讀:0 作者:zby909 欄目: JavaScript 歡迎投稿:712375056

示例:

tip: 該組件基于vue-cropper二次封裝

安裝插件

npm install vue-cropper

yarn add vue-cropper

寫(xiě)入封裝的組件

<!-- 簡(jiǎn)易圖片裁剪組件 --- 二次封裝 -->
<!-- 更多api https://github.com/xyxiao001/vue-cropper -->
<!-- 使用:傳入圖片 比例 顯示隱藏。方法:監聽(tīng)底部按鈕點(diǎn)擊即可  ---更多props查詢(xún)文檔自行添加 -->

<template>
  <div v-if="value" :value="value" @input="val => $emit('input', val)" class="conbox">
    <div class="info">
      <vueCropper
        ref="cropper"
        :img="img"
        :outputSize="outputSize"
        :outputType="outputType"
        :info="info"
        :canScale="canScale"
        :autoCrop="autoCrop"
        :fixed="fixed"
        :fixedNumber="fixedNumber"
        :full="full"
        :fixedBox="fixedBox"
        :canMove="canMove"
        :canMoveBox="canMoveBox"
        :original="original"
        :centerBox="centerBox"
        :infoTrue="infoTrue"
        :mode="mode"
      ></vueCropper>
    </div>
    <div class="btns">
      <div @click="clickCancelCut" class="cancel">取消</div>
      <img @click="clickRotate" src="../../assets/paradise/rotate.png" alt="" />
      <div @click="clickOk" class="okey">確定</div>
    </div>
  </div>
</template>

<script>
import { VueCropper } from 'vue-cropper';
export default {
  name: 'PictureCropping',
  components: { VueCropper },
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    //裁剪圖片的地址
    img: {
      type: String,
      default: '',
    },
    //截圖框的寬高比例
    fixedNumber: {
      type: Array,
      default: () => {
        return [1, 1];
      },
    },
  },
  data() {
    return {
      // 裁剪組件的基礎配置option
      //   img: this.img, // 裁剪圖片的地址
      outputSize: 1, // 裁剪生成圖片的質(zhì)量
      outputType: 'jpeg', // 裁剪生成圖片的格式
      info: true, // 裁剪框的大小信息
      canScale: true, // 圖片是否允許滾輪縮放
      autoCrop: true, // 是否默認生成截圖框
      // autoCropWidth: 300, // 默認生成截圖框寬度
      // autoCropHeight: 200, // 默認生成截圖框高度
      fixed: true, // 是否開(kāi)啟截圖框寬高固定比例
      //   fixedNumber: this.fixedNumber, // 截圖框的寬高比例
      full: true, // 是否輸出原圖比例的截圖
      fixedBox: true, // 固定截圖框大小 不允許改變
      canMove: true, //上傳圖片是否可以移動(dòng)
      canMoveBox: true, // 截圖框能否拖動(dòng)
      original: false, // 上傳圖片按照原始比例渲染
      centerBox: true, // 截圖框是否被限制在圖片里面
      // high:true,// 是否按照設備的dpr 輸出等比例圖片
      infoTrue: true, // true 為展示真實(shí)輸出圖片寬高 false 展示看到的截圖框寬高
      // maxImgSize: 2000, //限制圖片最大寬度和高度
      // enlarge: 1, //圖片根據截圖框輸出比例倍數
      mode: 'contain', //圖片默認渲染方式
    };
  },
  computed: {},
  watch: {},
  //生命周期 - 創(chuàng  )建完成(訪(fǎng)問(wèn)當前this實(shí)例)
  created() {},
  //生命周期 - 掛載完成(訪(fǎng)問(wèn)DOM元素)
  mounted() {},
  methods: {
    clickCancelCut() {
      this.$emit('clickCancelCut', '點(diǎn)擊取消');
      this.$refs.cropper.stopCrop();
      this.$refs.cropper.clearCrop();
    },
    clickRotate() {
      this.$refs.cropper.rotateRight();
      this.$emit('clickRotate', '點(diǎn)擊旋轉');
    },
    clickOk() {
      //輸出裁剪的base64
      this.$refs.cropper.getCropData(data => {
        this.$emit('clickOk', data);
        this.$refs.cropper.stopCrop();
        this.$refs.cropper.clearCrop();
      });
    },
  },
};
</script>
<style lang='less' scoped>
/* @import url(); 引入css類(lèi) */
.conbox {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  box-sizing: border-box;
  height: 100vh;
  width: 100%;
  background-color: #000;
  display: flex;
  flex-direction: column;
  justify-content: center;
  .info {
    width: auto;
    height: 800px;
    .vue-cropper {
      background-image: none;
      background-color: #000;
    }
  }
  .btns {
    padding: 0 20px;

    color: #fff;
    text-align: center;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 15px;
    img {
      width: 85px;
      height: 85px;
    }
    .cancel {
      background-color: #606465;
      padding: 15px 20px;
      width: 100px;
      border-radius: 10px;
    }
    .okey {
      background-color: #df6457;
      padding: 15px 20px;
      width: 100px;
      border-radius: 10px;
    }
  }
}
</style>

總結

到此這篇關(guān)于Vue圖片裁剪組件的文章就介紹到這了,更多相關(guān)Vue圖片裁剪組件內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。

免费国产A国产片高清网站| 漂亮人妻被中出中文字幕久久| 无码AV大香线蕉| 99精品国产高清一区二区| 亚洲AV永久无码精品一区二区| XXXX性BBBB欧美|