文档提供了fetch API的简单示例:
fetch('http://example.com/')
.then(function(res) {
return res.text();
})
.then(function(body) {
var output = {id: 1234, rawHTML: body};
callback(null, output);
})
.catch(callback);
查询数据。
如何在这些结构中添加标题或传递帖子数据?
答案 0 :(得分:0)
可以使用标准的Fetch API可能性(第二个参数是请求的选项,您可以传递标题,使用HTTP方法等),例如。
var myInit = { method: 'GET',
headers: {
authentication: 'Basic lkjbwkejbf...'
},
mode: 'cors',
cache: 'default' };
fetch('flowers.jpg', myInit).then(function(response) {
return response.blob();
}).then(function(myBlob) {
var objectURL = URL.createObjectURL(myBlob);
myImage.src = objectURL;
});
如描述here