vue实现移动端图片裁剪上传功能

2020-06-14 06:04:19易采站长站整理

top: 0;
bottom: 0;
left: 0;
right: 0;
background: #fff;
z-index: 99999;
display: none;
.layer-header {
position: absolute;
top: 0;
left: 0;
z-index: 99999;
background: #fff;
width: 100%;
height: .8rem;
padding: 0 .2rem;
box-sizing: border-box;
}
.cancel,
.confirm {
line-height: .8rem;
font-size: .28rem;
background: inherit;
border: 0;
outline: 0;
float: left;
}
.confirm {
float: right;
}
img {
position: inherit!important;
border-radius: inherit!important;
float: inherit!important;
}
}
}
</style>

3.引用组件


<template>
<simple-cropper :initParam="uploadParam" :successCallback="uploadHandle" ref="cropper">
<img :src="userImg" @click="upload">
</simple-cropper>
</template>

<script>
import SimpleCropper from '@/components/SimpleCropper'
export default {
name: 'info',
data () {
return {
uploadParam: {
fileType: 'recruit', // 其他上传参数
uploadURL: this.$dataURL + 'uploadAction/qcloudImg', // 上传地址
scale: 4 // 相对手机屏幕放大的倍数: 4倍
},
userImg: this.$dataURL + 'test.png'
}
},
methods: {
// 上传头像
upload () {
this.$refs['cropper'].upload()
},
// 上传头像成功回调
uploadHandle (data) {
if (data.state === 'SUCCESS') {
this.userImg = this.form.headImgUrl = data.fileId
}
}
},
components: {
SimpleCropper
}
}
</script>

4.示例图