/** 覆盖默认上传行为 */
function requestUpload() {}
/** 向左旋转 */
function rotateLeft() {
proxy.$refs.cropper.rotateLeft();
}
/** 向右旋转 */
function rotateRight() {
proxy.$refs.cropper.rotateRight();
}
/** 图片缩放 */
function changeScale(num) {
num = num || 1;
proxy.$refs.cropper.changeScale(num);
}
/** 上传预处理 */
function beforeUpload(file) {
if (file.type.indexOf("image/") == -1) {
proxy.$modal.msgError(
"文件格式错误,请上传图片类型,如:JPG,PNG后缀的文件。"
);
} else {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
options.img = reader.result;
};
}
}
/** 上传图片 */
function uploadImg() {
proxy.$refs.cropper.getCropBlob((data) => {
let formData = new FormData();
formData.append("avatarfile", data);
uploadAvatar(formData).then((response) => {
open.value = false;
options.img = import.meta.env.VITE_APP_BASE_API + response.imgUrl;
store.commit("SET_AVATAR", options.img);
proxy.$modal.msgSuccess("修改成功");
visible.value = false;
});
});
}
vue-cropper官网
博主说的很全 blog.csdn.net/qq_41107231…