需求:后台直接反悔了一张图片,文件流,前端需要显示这个图片,开始解析URL一直出错,最后发现,还需要设置个responseType参数才可解析出正确的url。
const formdata = new FormData();
formdata.append("content", this.state.text);
formdata.append("file", this.state.imageArr[0]);
axios({
method: "post",
url: "/api/qr-code",
data: formdata,
responseType: "blob",
}).then((res) => {
let blob = new Blob([res.data], { type: "image/png" });
let url = window.URL.createObjectURL(blob);
console.log(url);
this.setState({ url });
Toast.hide()
});
网友评论