亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue利用插件實(shí)現(xiàn)按比例切割圖片

 更新時(shí)間:2021年09月22日 11:27:05   作者:~小仙女~  
這篇文章主要為大家詳細(xì)介紹了vue利用插件實(shí)現(xiàn)按比例切割圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue利用插件實(shí)現(xiàn)按比例切割圖片的具體代碼,供大家參考,具體內(nèi)容如下

1.使用插件——vueCropper

安裝該插件:npm install vue-cropper
結(jié)合el-element的上傳組件

2.示例:

主頁(yè)面

data(){
 return {
     formData:{
        currentBannerImg:""
     },
     isShowCropper :false,
 }
}
<el-upload
      class="avatar-uploader"
      list-type="picture-card"
      action=""
      accept=".jpg, .jpeg, .png"
      :with-credentials="true"
      :on-change="fileChangeBanner"
      :auto-upload="false"
      :show-file-list="false"
    >
    <div class="imgBoX">
        <img class="bannerImg" v-if="formData.currentBannerImg" title="點(diǎn)擊更換" :src="formData.currentBannerImg" alt="" />
        <i class="el-icon-delete delImg" v-if="formData.currentBannerImg" title="刪除"></i>
        <i v-if="!formData.currentBannerImg" slot="default" class="el-icon-plus"></i>
      </div>
      <div slot="tip" class="el-upload__tip">只能上傳jpg、jpeg、png且單個(gè)文件不超過(guò)10M</div>
</el-upload>

// 上傳圖片,成功后調(diào)裁剪
    async fileChangeBanner(file, fileList) {
      const fileType = file.name.substring(file.name.lastIndexOf(".") + 1);
      const fileTypeArr = ["jpg", "jpeg", "png", "JPG", "JPEG", "PNG"];
      if (fileTypeArr.indexOf(fileType) < 0) {
        this.$alert("請(qǐng)上傳格式為jpg、jpeg、png的圖片!", "系統(tǒng)提示", {
          confirmButtonText: "確定"
        });
        fileList.splice(fileList.length - 1);
        return;
      }
      // 大小限制
      const isLt2M = file.size / 1024 / 1024 < this.$FileSize;
      if (!isLt2M) {
        this.$alert(`上傳文件大小不能超過(guò) ${this.$FileSize}MB!`, "系統(tǒng)提示", {
          confirmButtonText: "確定"
        });
        fileList.splice(fileList.length - 1);
        return;
      }
      // 添加裁剪部分
      this.isShowCropper = true;
      this.$nextTick(() => {
        this.$refs.vueCropperDialog.open(file);
      });
    },

vueCropperDialog作為組件被引入

<vueCropperDialog @cutImgEnter="cutImgEnter" v-if="isShowCropper" ref="vueCropperDialog"></vueCropperDialog>

vueCropperDialog.vue

<!--  -->
<template>
  <!-- vueCropper 剪裁圖片實(shí)現(xiàn)-->
  <el-dialog title="圖片剪裁" :visible.sync="dialogVisible" append-to-body>
    <div class="cropper-content">
      <div class="cropper" style="text-align:center">
        <vueCropper
          ref="cropper"
          :img="option.img"
          :outputSize="option.size"
          :outputType="option.outputType"
          :info="true"
          :full="option.full"
          :canMove="option.canMove"
          :canMoveBox="option.canMoveBox"
          :original="option.original"
          :autoCrop="option.autoCrop"
          :fixed="option.fixed"
          :fixedNumber="option.fixedNumber"
          :centerBox="option.centerBox"
          :infoTrue="option.infoTrue"
          :fixedBox="option.fixedBox"
        ></vueCropper>
      </div>
    </div>
    <div slot="footer" class="dialog-footer btnBox">
      <div>
        <el-button icon="el-icon-refresh-left" @click="turnLeftOrRight('left')">左旋轉(zhuǎn)</el-button>
        <el-button icon="el-icon-refresh-right" @click="turnLeftOrRight('right')">右旋轉(zhuǎn)</el-button>
      </div>
      <div>
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="finish" :loading="loading">確認(rèn)</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      fileinfo:"",
      dialogVisible: false,
      // 裁剪組件的基礎(chǔ)配置option
      option: {
        img: "", // 裁剪圖片的地址
        info: true, // 裁剪框的大小信息
        outputSize: 0.8, // 裁剪生成圖片的質(zhì)量
        outputType: "jpeg", // 裁剪生成圖片的格式
        canScale: false, // 圖片是否允許滾輪縮放
        autoCrop: true, // 是否默認(rèn)生成截圖框
        // autoCropWidth: 563, // 默認(rèn)生成截圖框?qū)挾?
        // autoCropHeight: 387, // 默認(rèn)生成截圖框高度
        fixedBox: true, // 固定截圖框大小 不允許改變
        fixed: true, // 是否開(kāi)啟截圖框?qū)捀吖潭ū壤?
        fixedNumber: [1.45, 1], // 截圖框的寬高比例
        full: true, // 是否輸出原圖比例的截圖
        canMoveBox: false, // 截圖框能否拖動(dòng)
        original: false, // 上傳圖片按照原始比例渲染
        centerBox: false, // 截圖框是否被限制在圖片里面
        infoTrue: true // true 為展示真實(shí)輸出圖片寬高 false 展示看到的截圖框?qū)捀?
      },
      picsList: [], //頁(yè)面顯示的數(shù)組
      // 防止重復(fù)提交
      loading: false
    };
  },
  methods: {
    open(file) {
      this.fileinfo = file;
      this.option.img = file.url;
      this.dialogVisible = true;
    },
    blobToFile(theBlob, file) {
      const files = new window.File([theBlob], file.name, { type: theBlob.type });
      return files;
    },
    //左旋轉(zhuǎn)
    turnLeftOrRight(type) {
      if (type == "left") {
        this.$refs.cropper.rotateLeft();
      } else {
        this.$refs.cropper.rotateRight();
      }
    },
    // 點(diǎn)擊裁剪,這一步是可以拿到處理后的地址
    finish() {
      this.$refs.cropper.getCropBlob((data) => {
        this.loading = true;
        const changeFile = this.blobToFile(data, this.fileinfo);
        const fielUrl = window.URL.createObjectURL(data);
        //裁剪成功后的回調(diào)
        this.$emit("cutImgEnter", changeFile, fielUrl);
        this.loading = false;
        this.dialogVisible = false;
      });
    }
  }
};
</script>
<style lang="scss" scoped>
// 截圖
.cropper-content {
  .cropper {
    width: auto;
    height: 300px;
  }
}
.btnBox {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
</style>

3.效果

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue+drf+第三方滑動(dòng)驗(yàn)證碼接入的實(shí)現(xiàn)

    vue+drf+第三方滑動(dòng)驗(yàn)證碼接入的實(shí)現(xiàn)

    這篇文章要給大家介紹的是vue和drf以及第三方滑動(dòng)驗(yàn)證碼接入的實(shí)現(xiàn),下文小編講詳細(xì)講解該內(nèi)容,感興趣的小伙伴可以和小編一起來(lái)學(xué)習(xí)奧
    2021-10-10
  • Vue中的@blur/@focus事件解讀

    Vue中的@blur/@focus事件解讀

    這篇文章主要介紹了Vue中的@blur/@focus事件解讀,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • Vue中使用及封裝websocket示例詳解

    Vue中使用及封裝websocket示例詳解

    這篇文章主要為大家介紹了Vue中使用及封裝websocket示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07
  • VUE如何將方法名字作為變量進(jìn)行調(diào)用

    VUE如何將方法名字作為變量進(jìn)行調(diào)用

    這篇文章主要介紹了VUE如何將方法名字作為變量進(jìn)行調(diào)用問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • 解決vue打包項(xiàng)目后刷新404的問(wèn)題

    解決vue打包項(xiàng)目后刷新404的問(wèn)題

    下面小編就為大家整理了一篇解決vue打包項(xiàng)目后刷新404的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-03-03
  • Vue.js 中制作自定義選擇組件的代碼附演示demo

    Vue.js 中制作自定義選擇組件的代碼附演示demo

    這篇文章主要介紹了Vue.js 中制作自定義選擇組件的代碼附演示demo,通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-02-02
  • vuejs父子組件之間數(shù)據(jù)交互詳解

    vuejs父子組件之間數(shù)據(jù)交互詳解

    這篇文章主要為大家詳細(xì)介紹了vuejs父子組件之間的數(shù)據(jù)交互,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • vue3+echarts實(shí)現(xiàn)漸變色環(huán)形圖過(guò)程

    vue3+echarts實(shí)現(xiàn)漸變色環(huán)形圖過(guò)程

    這篇文章主要介紹了vue3+echarts實(shí)現(xiàn)漸變色環(huán)形圖過(guò)程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • Element-UI踩坑之Pagination組件的使用

    Element-UI踩坑之Pagination組件的使用

    這篇文章主要介紹了Element-UI踩坑之Pagination組件,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-10-10
  • Vue動(dòng)態(tài)表單的應(yīng)用詳解

    Vue動(dòng)態(tài)表單的應(yīng)用詳解

    這篇文章主要為大家詳細(xì)介紹了Vue動(dòng)態(tài)表單的應(yīng)用,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-10-10

最新評(píng)論