// 请求路径 
  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)

  

相关文章:

  • 2021-12-10
  • 2022-12-23
  • 2021-08-23
  • 2022-02-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
  • 2021-09-22
  • 2022-12-23
相关资源
相似解决方案