本文主要是介绍【fetch】浏览器默认请求方式,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
fetch 参数体:
method: "POST", // *GET, POST, PUT, DELETE, etc.mode: "cors", // no-cors, *cors, same-origincache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cachedcredentials: "same-origin", // include, *same-origin, omitheaders: {"Content-Type": "application/json",// 'Content-Type': 'application/x-www-form-urlencoded',},redirect: "follow", // manual, *follow, errorreferrerPolicy: "no-referrer", // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-urlbody: JSON.stringify(data), // body data type must match "Content-Type" header
fetch GET
fetch(`http://xxx/list?pageNo=1&pageSize=10`, {method: 'GET',headers: {Authorization: token.value}}).then(res => {return res.json()})
fetch POST
fetch(`http://xxx/post`, {method: 'POST',headers: {Authorization: token.value,'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'},body: `id=${id}&xxx={value}`}).then(res => {return res.json()})
这篇关于【fetch】浏览器默认请求方式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!