最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue-cropper實(shí)現(xiàn)裁剪圖片

 更新時(shí)間:2022年05月18日 15:11:40   作者:-Dayer-  
這篇文章主要為大家詳細(xì)介紹了vue-cropper實(shí)現(xiàn)裁剪圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue-cropper實(shí)現(xiàn)裁剪圖片的具體代碼,供大家參考,具體內(nèi)容如下

先展示一下效果

如何使用:

1、安裝 

npm install vue-cropper  //(如果安裝不上,用cnpm)

2、直接貼代碼爽快人就是這樣

<template>
? <el-dialog
? ? title="裁剪圖片"
? ? :visible.sync="visible"
? ? @close="onCallback(false)"
? ? class="handleDialog"
? ? width="1000px"
? >
? ? <div class="wrap">
? ? ? <div class="main">
? ? ? ? <div class="cropperContent">
? ? ? ? ? <div class="cropper">
? ? ? ? ? ? <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"
? ? ? ? ? ? ? :autoCropWidth="option.autoCropWidth"
? ? ? ? ? ? ? :autoCropHeight="option.autoCropHeight"
? ? ? ? ? ? ? :fixedBox="option.fixedBox"
? ? ? ? ? ? ? @realTime="realTime"
? ? ? ? ? ? ? @imgLoad="imgLoad"
? ? ? ? ? ? ></vueCropper>
? ? ? ? ? </div>
? ? ? ? ? <div class="previewBox">
? ? ? ? ? ? <div class="title">實(shí)時(shí)預(yù)覽</div>
? ? ? ? ? ? <div
? ? ? ? ? ? ? class="showPreview"
? ? ? ? ? ? ? :style="{
? ? ? ? ? ? ? ? width: previews.w + 'px',
? ? ? ? ? ? ? ? height: previews.h + 'px',
? ? ? ? ? ? ? }"
? ? ? ? ? ? >
? ? ? ? ? ? ? <div :style="previews.div" class="preview">
? ? ? ? ? ? ? ? <img :src="previews.url" :style="previews.img" />
? ? ? ? ? ? ? </div>
? ? ? ? ? ? </div>
? ? ? ? ? </div>
? ? ? ? </div>
?
? ? ? ? <div class="footerButton">
? ? ? ? ? <div class="scopeButton">
? ? ? ? ? ? <label class="localButton" for="uploads">本地圖片</label>
? ? ? ? ? ? <input
? ? ? ? ? ? ? type="file"
? ? ? ? ? ? ? id="uploads"
? ? ? ? ? ? ? class="inputFile"
? ? ? ? ? ? ? accept="image/png, image/jpeg, image/gif, image/jpg"
? ? ? ? ? ? ? @change="uploadImg($event)"
? ? ? ? ? ? />
?
? ? ? ? ? ? <el-button
? ? ? ? ? ? ? type="primary"
? ? ? ? ? ? ? @click="changeScale(1)"
? ? ? ? ? ? ? icon="el-icon-plus"
? ? ? ? ? ? ></el-button>
? ? ? ? ? ? <el-button
? ? ? ? ? ? ? type="primary"
? ? ? ? ? ? ? @click="changeScale(-1)"
? ? ? ? ? ? ? icon="el-icon-minus"
? ? ? ? ? ? ></el-button>
? ? ? ? ? ? <el-button
? ? ? ? ? ? ? type="primary"
? ? ? ? ? ? ? @click="rotateLeft"
? ? ? ? ? ? ? icon="el-icon-refresh-left"
? ? ? ? ? ? ></el-button>
? ? ? ? ? ? <el-button
? ? ? ? ? ? ? type="primary"
? ? ? ? ? ? ? @click="rotateRight"
? ? ? ? ? ? ? icon="el-icon-refresh-right"
? ? ? ? ? ? ></el-button>
? ? ? ? ? </div>
? ? ? ? ? <div class="uploadButton">
? ? ? ? ? ? <el-button
? ? ? ? ? ? ? @click="down('blob')"
? ? ? ? ? ? ? type="primary"
? ? ? ? ? ? ? icon="el-icon-download"
? ? ? ? ? ? ? >下載</el-button
? ? ? ? ? ? >
? ? ? ? ? ? <el-button
? ? ? ? ? ? ? @click="uploadNewPic"
? ? ? ? ? ? ? type="primary"
? ? ? ? ? ? ? icon="el-icon-upload2"
? ? ? ? ? ? ? >上傳</el-button
? ? ? ? ? ? >
? ? ? ? ? </div>
? ? ? ? </div>
? ? ? </div>
? ? ? <div class="end">
? ? ? ? <el-button type="primary" @click="saveNewPic">保存</el-button>
? ? ? ? <el-button @click="onCallback(false)">取消</el-button>
? ? ? </div>
? ? </div>
? </el-dialog>
</template>
<script>
import { VueCropper } from "vue-cropper";
import { imgView, imgUploadUrl, uploadImg } from "services";
import { alerts } from "js/yydjs.js";
export default {
? components: { VueCropper },
? data() {
? ? return {
? ? ? imgView,
? ? ? picId: "",
? ? ? newPicId: "",
? ? ? crap: false,
? ? ? previews: {},
? ? ? option: {
? ? ? ? img: "",
? ? ? ? size: 1,
? ? ? ? full: false, //輸出原圖比例截圖 props名full
? ? ? ? outputType: "png",
? ? ? ? canMove: true,
? ? ? ? original: false,
? ? ? ? canMoveBox: false,
? ? ? ? autoCrop: true,
? ? ? ? autoCropWidth: 300,
? ? ? ? autoCropHeight: 300,
? ? ? ? fixedBox: true,
? ? ? },
? ? ? downImg: "#",
? ? ? cate: "",
? ? ? ratio: 1,
? ? };
? },
? mounted() {
? ? this.option.img = this.imgView + this.picId;
? ? this.option.autoCropHeight = this.option.autoCropWidth * this.ratio;
? },
? methods: {
? ? saveNewPic() {
? ? ? if (!this.newPicId) {
? ? ? ? return alerts("請(qǐng)上傳裁剪后的圖片");
? ? ? }
? ? ? this.onCallback(this.newPicId);
? ? },
? ? changeScale(num) {
? ? ? num = num || 1;
? ? ? this.$refs.cropper.changeScale(num);
? ? },
? ? rotateLeft() {
? ? ? this.$refs.cropper.rotateLeft();
? ? },
? ? rotateRight() {
? ? ? this.$refs.cropper.rotateRight();
? ? },
? ? // 實(shí)時(shí)預(yù)覽函數(shù)
? ? realTime(data) {
? ? ? console.log(data, "realTime");
? ? ? this.previews = data;
? ? },
? ? // 將base64轉(zhuǎn)換為文件 百度隨便找的 看需求使用
? ? dataURLtoFile(dataurl, filename) {
? ? ? var arr = dataurl.split(","),
? ? ? ? mime = arr[0].match(/:(.*?);/)[1],
? ? ? ? bstr = atob(arr[1]),
? ? ? ? n = bstr.length,
? ? ? ? u8arr = new Uint8Array(n);
? ? ? while (n--) {
? ? ? ? u8arr[n] = bstr.charCodeAt(n);
? ? ? }
? ? ? return new File([u8arr], filename, { type: mime });
? ? },
? ? uploadNewPic() {
? ? ? this.$refs.cropper.getCropData((data) => {
? ? ? ? let name = new Date().getTime();
? ? ? ? let file = this.dataURLtoFile(data, `${name}.png`);
? ? ? ? console.log(file, "ssss");
? ? ? ? let fd = new FormData();
? ? ? ? fd.append("file", file);
? ? ? ? fd.append("cate", this.cate);
? ? ? ? uploadImg(fd).then((res) => {
? ? ? ? ? if (res) {
? ? ? ? ? ? let { scaleRelativePath = "" } = res.body;
? ? ? ? ? ? this.newPicId = scaleRelativePath;
? ? ? ? ? ? alerts("上傳成功", "success"); // 自己寫(xiě)的彈框
? ? ? ? ? }
? ? ? ? });
? ? ? });
? ? },
? ? down(type) {
? ? ? // event.preventDefault()
? ? ? var aLink = document.createElement("a");
? ? ? aLink.download = "author-img";
? ? ? // 輸出
? ? ? if (type === "blob") {
? ? ? ? this.$refs.cropper.getCropBlob((data) => {
? ? ? ? ? console.log(data, type);
? ? ? ? ? this.downImg = window.URL.createObjectURL(data);
? ? ? ? ? // aLink.download = this.downImg;
? ? ? ? ? console.log(this.downImg);
? ? ? ? ? aLink.href = window.URL.createObjectURL(data);
? ? ? ? ? aLink.click();
? ? ? ? });
? ? ? } else {
? ? ? ? this.$refs.cropper.getCropData((data) => {
? ? ? ? ? this.downImg = data;
? ? ? ? ? aLink.href = data;
? ? ? ? ? aLink.click();
? ? ? ? });
? ? ? }
? ? },
? ? uploadImg(e) {
? ? ? //上傳圖片
? ? ? // this.option.img
? ? ? var file = e.target.files[0];
? ? ? if (!/\.(gif|jpg|jpeg|png|bmp|GIF|JPG|PNG)$/.test(e.target.value)) {
? ? ? ? alerts("圖片類型必須是.gif,jpeg,jpg,png,bmp中的一種");
? ? ? ? return false;
? ? ? }
? ? ? var reader = new FileReader();
? ? ? reader.onload = (e) => {
? ? ? ? let data;
? ? ? ? if (typeof e.target.result === "object") {
? ? ? ? ? // 把Array Buffer轉(zhuǎn)化為blob 如果是base64不需要
? ? ? ? ? data = window.URL.createObjectURL(new Blob([e.target.result]));
? ? ? ? } else {
? ? ? ? ? data = e.target.result;
? ? ? ? }
? ? ? ? this.option.img = data;
? ? ? };
? ? ? // 轉(zhuǎn)化為base64
? ? ? // reader.readAsDataURL(file)
? ? ? // 轉(zhuǎn)化為blob
? ? ? reader.readAsArrayBuffer(file);
? ? },
? ? imgLoad(msg) {
? ? ? console.log(msg, "msg");
? ? },
? },
};
</script>
<style lang="scss" scoped>
@import "~css/public.scss";
.handleDialog {
? @include cententCenterDialog;
? .cropperContent {
? ? display: flex;
? ? justify-content: space-between;
? ? padding-left: 20px;
? ? .cropper {
? ? ? width: 400px;
? ? ? height: 400px;
? ? ? border: 1px solid #ddd;
? ? }
? ? .previewBox {
? ? ? flex: 1;
? ? ? display: flex;
? ? ? justify-content: center;
? ? ? flex-direction: column;
? ? ? align-items: center;
? ? ? .title {
? ? ? ? font-size: 18px;
? ? ? ? height: 36px;
? ? ? ? margin-bottom: 20px;
? ? ? }
? ? ? .showPreview {
? ? ? ? flex: 1;
? ? ? ? display: flex;
? ? ? ? justify-content: center;
? ? ? ? .preview {
? ? ? ? ? overflow: hidden;
? ? ? ? ? background: #eeeeee;
? ? ? ? ? border: 1px solid #eeeeee;
? ? ? ? }
? ? ? }
? ? }
? }
? .footerButton {
? ? margin-top: 30px;
? ? margin-left: 20px;
? ? display: flex;
? ? justify-content: flex-end;
? ? .scopeButton {
? ? ? width: 400px;
? ? ? display: flex;
? ? ? justify-content: space-between;
? ? }
? ? .uploadButton {
? ? ? flex: 1;
? ? ? display: flex;
? ? ? justify-content: center;
? ? }
? ? .localButton {
? ? ? cursor: pointer;
? ? ? color: #ffffff;
? ? ? background: #409eff;
? ? ? padding: 10px 15px;
? ? ? border-radius: 3px;
? ? ? appearance: none;
? ? ? display: flex;
? ? ? align-self: center;
? ? ? margin-right: 10px;
? ? }
? ? .inputFile {
? ? ? width: 180px;
? ? ? position: absolute;
? ? ? clip: rect(0 0 0 0);
? ? }
? }
}
</style>

3、說(shuō)明,支持網(wǎng)絡(luò)圖片也支持本地圖片,圖片如果需要上傳,我是通過(guò)base64轉(zhuǎn)文件,再上傳的。

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

相關(guān)文章

  • 詳解vue2.6插槽更新v-slot用法總結(jié)

    詳解vue2.6插槽更新v-slot用法總結(jié)

    在 2.6.0 中,我們?yōu)榫呙宀酆妥饔糜虿宀垡肓艘粋€(gè)新的統(tǒng)一的語(yǔ)法 (即 v-slot 指令)。這篇文章主要介紹了詳解vue2.6插槽更新v-slot用法總結(jié),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-03-03
  • vue使用高德地圖根據(jù)坐標(biāo)定位點(diǎn)的實(shí)現(xiàn)代碼

    vue使用高德地圖根據(jù)坐標(biāo)定位點(diǎn)的實(shí)現(xiàn)代碼

    這篇文章主要介紹了vue使用高德地圖根據(jù)坐標(biāo)定位點(diǎn)的實(shí)現(xiàn)代碼,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-08-08
  • Vue的子父組件傳值之小白必看篇

    Vue的子父組件傳值之小白必看篇

    這篇文章主要介紹了Vue的子父組件傳值之小白必看篇,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • vue實(shí)現(xiàn)微信公眾號(hào)h5跳轉(zhuǎn)小程序的示例代碼

    vue實(shí)現(xiàn)微信公眾號(hào)h5跳轉(zhuǎn)小程序的示例代碼

    本文主要介紹了vue實(shí)現(xiàn)微信公眾號(hào)h5跳轉(zhuǎn)小程序的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • 從vue源碼看props的用法

    從vue源碼看props的用法

    平時(shí)寫(xiě)vue的時(shí)候知道 props 有很多種用法,今天我們來(lái)看看vue內(nèi)部是怎么處理 props 中那么多的用法的。非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2019-01-01
  • Vue之mixin混入詳解

    Vue之mixin混入詳解

    這篇文章主要為大家介紹了Vue之mixin混入,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2021-11-11
  • vue3+vite 動(dòng)態(tài)引用靜態(tài)資源及動(dòng)態(tài)引入assets文件夾圖片的多種方式

    vue3+vite 動(dòng)態(tài)引用靜態(tài)資源及動(dòng)態(tài)引入assets文件夾圖片的多種方式

    通過(guò)require動(dòng)態(tài)引入, 發(fā)現(xiàn)報(bào)錯(cuò):require is not defind,這是因?yàn)?nbsp;require 是屬于 Webpack 的方法,本文給大家介紹vue3+vite 動(dòng)態(tài)引用靜態(tài)資源及動(dòng)態(tài)引入assets文件夾圖片的多種方式,感興趣的朋友一起看看吧
    2023-10-10
  • Vue中props報(bào)錯(cuò)問(wèn)題解決方案

    Vue中props報(bào)錯(cuò)問(wèn)題解決方案

    這篇文章主要介紹了Vue中props報(bào)錯(cuò)問(wèn)題解決方案,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-09-09
  • Vue如何接入hls/m3u8的直播視頻詳解

    Vue如何接入hls/m3u8的直播視頻詳解

    項(xiàng)目中有一個(gè)需求,需要實(shí)現(xiàn)直播功能,后端接口返回的是m3u8數(shù)據(jù)流,下面這篇文章主要給大家介紹了關(guān)于Vue如何接入hls/m3u8直播視頻的相關(guān)資料,需要的朋友可以參考下
    2022-07-07
  • 使用Vue實(shí)現(xiàn)點(diǎn)擊按鈕小球加入購(gòu)物車動(dòng)畫(huà)

    使用Vue實(shí)現(xiàn)點(diǎn)擊按鈕小球加入購(gòu)物車動(dòng)畫(huà)

    這篇文章主要為大家詳細(xì)介紹了如何使用Vue實(shí)現(xiàn)點(diǎn)擊按鈕小球加入購(gòu)物車動(dòng)畫(huà),文中的示例代碼講解詳細(xì),有需要的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-03-03

最新評(píng)論

洛隆县| 常宁市| 南召县| 镇平县| 西和县| 连城县| 资兴市| 拉孜县| 酒泉市| 二连浩特市| 霍林郭勒市| 白玉县| 墨脱县| 吐鲁番市| 肥城市| 镇沅| 呼伦贝尔市| 新乡市| 枣阳市| 五常市| 鞍山市| 普兰店市| 松江区| 克拉玛依市| 乳山市| 肃宁县| 高尔夫| 呈贡县| 叙永县| 玉山县| 邳州市| 博乐市| 琼结县| 齐齐哈尔市| 三都| 中宁县| 肇庆市| 河曲县| 当雄县| 公安县| 沾益县|