1 回答

TA貢獻1856條經驗 獲得超5個贊
fetch還接受第二個參數,它是一個文字對象,包含與請求有關的信息——例如請求方法、模式、標頭和 POST BODY。
直接來自 Mozilla 文檔:
var data = { name: "justin", code: "SDF", type: "some-type" };
fetch(url, {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json'
// 'Content-Type': 'application/x-www-form-urlencoded',
},
body: JSON.stringify(data) // body data type must match "Content-Type" header
});
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
添加回答
舉報