Q1。在异步 JavaScript 和需要从客户端“获取”数据的情况下,为什么我们不能通过其属性来编辑我们的图像元素src
?
Q2。为什么必须经过 Blob 转换过程?
Q3。什么是 blob 角色?
例如,从 JSON 中检索图像文件。(顺便说一句,我是从 MDN 网页中提取的,请注意评论)
function fetchBlob(product) {
// construct the URL path to the image file from the product.image property
let url = 'images/' + product.image;
// Use fetch to fetch the image, and convert the resulting response to a blob
// Again, if any errors occur we report them in the console.
fetch(url).then(function(response) {
return response.blob();
}).then(function(blob) {
// Convert the blob to an object URL — this is basically an temporary internal URL
// that points to an object stored inside the browser
let objectURL = URL.createObjectURL(blob);
// invoke showProduct
showProduct(objectURL, product);
});
}