欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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("請上傳裁剪后的圖片");
? ? ? }
? ? ? 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"); // 自己寫的彈框
? ? ? ? ? }
? ? ? ? });
? ? ? });
? ? },
? ? 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、說明,支持網(wǎng)絡(luò)圖片也支持本地圖片,圖片如果需要上傳,我是通過base64轉(zhuǎn)文件,再上傳的。

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

相關(guān)文章

  • vue-router路由傳參及隱藏參數(shù)問題

    vue-router路由傳參及隱藏參數(shù)問題

    這篇文章主要介紹了vue-router路由傳參及隱藏參數(shù)問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • vue-router使用next()跳轉(zhuǎn)到指定路徑時(shí)會(huì)無限循環(huán)問題

    vue-router使用next()跳轉(zhuǎn)到指定路徑時(shí)會(huì)無限循環(huán)問題

    這篇文章主要介紹了vue-router使用next()跳轉(zhuǎn)到指定路徑時(shí)會(huì)無限循環(huán)問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • Vue Echarts簡易實(shí)現(xiàn)儀表盤

    Vue Echarts簡易實(shí)現(xiàn)儀表盤

    這篇文章主要為大家詳細(xì)介紹了Vue Echarts實(shí)現(xiàn)儀表盤案例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-12-12
  • Vue導(dǎo)出json數(shù)據(jù)到Excel電子表格的示例

    Vue導(dǎo)出json數(shù)據(jù)到Excel電子表格的示例

    本篇主要介紹了Vue導(dǎo)出json數(shù)據(jù)到Excel電子表格的示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-12-12
  • 基于Vue實(shí)現(xiàn)可選擇不連續(xù)的時(shí)間范圍的日期選擇器

    基于Vue實(shí)現(xiàn)可選擇不連續(xù)的時(shí)間范圍的日期選擇器

    這篇文章主要為大家詳細(xì)介紹了如何基于Vue.js實(shí)現(xiàn)一個(gè)可選擇不連續(xù)的時(shí)間范圍的日期選擇器,文中的示例代碼簡潔易懂,需要的可以參考一下
    2023-06-06
  • element ui table(表格)實(shí)現(xiàn)點(diǎn)擊一行展開功能

    element ui table(表格)實(shí)現(xiàn)點(diǎn)擊一行展開功能

    這篇文章主要給大家介紹了關(guān)于element ui table(表格)實(shí)現(xiàn)點(diǎn)擊一行展開功能的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-12-12
  • Vue前端高效開發(fā)之列表渲染指令

    Vue前端高效開發(fā)之列表渲染指令

    這篇文章主要給大家介紹了關(guān)于Vue前端高效開發(fā)之列表渲染指令的相關(guān)資料,vue.js 使用的是 v-for 指令來處理組件元素的循環(huán)迭代邏輯,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2021-06-06
  • vue初始化動(dòng)畫加載的實(shí)例

    vue初始化動(dòng)畫加載的實(shí)例

    今天小編就為大家分享一篇vue初始化動(dòng)畫加載的實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • Vue.js原理分析之observer模塊詳解

    Vue.js原理分析之observer模塊詳解

    這篇文章主要介紹了Vue.js中observer模塊的相關(guān)資料,文中通過原理分析介紹還是相對的詳細(xì),相信對大家具有一定的參考價(jià)值,需要的朋友們下面來一起看看吧。
    2017-02-02
  • 詳解VUE-地區(qū)選擇器(V-Distpicker)組件使用心得

    詳解VUE-地區(qū)選擇器(V-Distpicker)組件使用心得

    這篇文章主要介紹了詳解VUE-地區(qū)選擇器(V-Distpicker)組件使用心得,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-05-05

最新評論