var that = this;
// 判断类型是不是图片
if (!/image\/\w+/.test(file.type)) {
that.$message("请确保文件为图像类型");
return false;
} else {
var article_image, image_base64;
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function (e) {
image_base64 = this.result.split(",")[1];
article_image = image_base64;
var params = {
imgdata: article_image
};
that.$axios.post(that.api + 'upload', params)
.then(res => {
if (res.data.status == 1) {
that.shareimg = res.data.result.url;
that.$message.success(res.data.message);
} else if (res.data.status == 0) {
this.$message.error(res.data.message);
}
})
.catch(error => {
})
}
}
判断是否为图片 和 转换base64
最新推荐文章于 2024-08-16 10:22:02 发布