// 请求路径
let url = 'http://jsonplaceholder.typicode.com/users' // 传输数据参数 const dataName = { name: "Sara", username: "高大丫", email: "35565451@qq.com" }; //封装fetch请求数据方法 class classFetch { // fetchFun(请求路径,请求方法,传输数据参数) fetchFun(url, meth, val) { return new Promise((resolve, reject) => { fetch(url, { method: meth, headers: { 'Content-type': 'application/json' }, body: JSON.stringify(val) }) .then(response => response.json()) .then(data => resolve(data)) .catch(err => reject(err)) }) } } const fetchObj = new classFetch() fetchObj.fetchFun(url, 'POST', dataName)
原文地址:https://www.cnblogs.com/gqx-html/p/11288955.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。