-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Improve the picture cropping component (#463)
* fix: Improve the picture cropping component * fix: component /verify/rotate text show problem
- Loading branch information
1 parent
ee1c349
commit 700306b
Showing
3 changed files
with
62 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,60 @@ | ||
<template> | ||
<PageWrapper title="图片裁剪示例" contentBackground> | ||
<CropperImage src="https://fengyuanchen.github.io/cropperjs/images/picture.jpg" /> | ||
<div class="cropper-container"> | ||
<CropperImage ref="refCropper" src="https://fengyuanchen.github.io/cropperjs/images/picture.jpg" @cropperedInfo="cropperedInfo" style="width:40%" /> | ||
<a-button type="primary" @click="onCropper"> 裁剪 </a-button> | ||
<img :src="cropperImg" class="croppered" v-if="cropperImg" /> | ||
</div> | ||
<p v-if="cropperImg">裁剪后图片信息:{{ info }}</p> | ||
</PageWrapper> | ||
</template> | ||
<script lang="ts"> | ||
import { defineComponent } from 'vue'; | ||
import { defineComponent, ref, onBeforeMount, getCurrentInstance } from 'vue'; | ||
import { PageWrapper } from '/@/components/Page'; | ||
import { CropperImage } from '/@/components/Cropper'; | ||
import img from '/@/assets/images/header.jpg'; | ||
export default defineComponent({ | ||
components: { | ||
PageWrapper, | ||
CropperImage, | ||
}, | ||
setup() { | ||
return { img }; | ||
let vm: any; | ||
let info = ref(""); | ||
let cropperImg = ref(""); | ||
const onCropper = (): void => { | ||
vm.refs.refCropper.croppered(); | ||
} | ||
onBeforeMount(()=>{ | ||
vm = getCurrentInstance(); | ||
}) | ||
function cropperedInfo({ imgBase64, imgInfo }) { | ||
info.value = imgInfo | ||
cropperImg.value = imgBase64 | ||
} | ||
return { | ||
img, | ||
info, | ||
cropperImg, | ||
onCropper, | ||
cropperedInfo | ||
}; | ||
}, | ||
}); | ||
</script> | ||
|
||
<style scoped> | ||
.cropper-container { | ||
display:flex; | ||
justify-content: space-around; | ||
align-items: center; | ||
} | ||
.croppered { | ||
width: 50%; | ||
height: 100%; | ||
} | ||
</style> |