open() {
var that = this;
uni.chooseImage({
count: 1,
sizeType: ["original", "compressed"],
// sourceType: ["camera"],
success: function (e) {
uni.showLoading({
title: "上传中...",
});
uni.uploadFile({
url: "https://*************/files/upload",
filePath: e.tempFilePaths[0],
fileType: "image",
timeout: 5000,
name: "files",
header: {
token: uni.getStorageSync("token"),
},
success: (res) => {
uni.hideLoading();
uni.showToast({
title: "上传成功",
icon: "none",
});
let data = JSON.parse(res.data);
if (data.errorCode == 200) {
that.$emit("imglist", data.data[0]);
that.imglist = data.data[0];
}
},
fail(err) {
console.log(err);
uni.hideLoading();
uni.showToast({
title: "上传失败" + err.errMsg,
icon: "none",
});
},
});
},
});
},
移动端上传图片
于 2024-08-30 11:36:39 首次发布