index.vue
1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<template>
<PageWrapper title="图片裁剪示例" contentBackground>
<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, 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() {
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>