const upload = async (url, formData) => {
    fetch(url, {
        method: 'POST',
        headers: {
          'content-Type': 'multipart/form-data',
        },
        body: formData,
      })
      .then(response => (response.json()))
      .catch(error => {
          console.log(error);
      });
};想将返回的值为json对象

解决方案 »

  1.   

    const upload = async (url, formData) => {
            return await fetch(url, {
                method: 'POST',
                headers: {
                    'content-Type': 'multipart/form-data',
                },
                body: formData,
            }).then(response => (response.json()))
        };
        upload('../FE/2018/testdata/abortcontroller.json',{})
            .then(console.log);