uploadFile(event) {
event.preventDefault();
this.fd = new FormData(); //内置方法new FormData() 新建一个表格
const files = event.target.files;
// 文件大小限制
if (files[0].size > 2 * 1024 * 1024) {
this.$message.error("文件大小不能超过2M");
return;
}
this.file = event.target.files[0]; // 获取上传的图片文件对象
const image = new Image();
image.src = URL.createObjectURL(this.file); // 设置图片源路径
image.onload = () => {
if (image.width >= image.height) {
this.isHorizontal = true; // 图片为横向
console.log("图片为横向");
this.fd.append("file", files[0]);
this.loading = true;
file(this.fd).then((res) => {
if (res.data.code == 200) {
console.log(res)
}
});
} else {
this.isHorizontal = false; // 图片不是横向
console.log("图片是纵向");
}
URL.revokeObjectURL(image.src); // 清除内存中的临时URL地址
};
},
09-19
476

11-12
8096
