[js] FormData method introduction and use:


1. The interface uses FormData to submit data:

insert image description here
insert image description here

2. Overview of FormData:

insert image description here
insert image description here
insert image description here
insert image description here

3. FormData case:

let formData = new FormData()
for (const key in that.model) {
    
     //that.model要遍历提交的对象
   if (Object.hasOwnProperty.call(that.model, key)) {
    
    
      const value = that.model[key];
      if (Array.isArray(value)) {
    
    
         formData.append(`${
     
     key}`, JSON.stringify(value))
      } else {
    
    
         formData.append(`${
     
     key}`, value)
      }
   }
}

Note: FormData submission parameters Content-Typewill automatically become 'multipart/form-data; boundary=----WebKitFormBoundaryhrtxY9vbYTZANhHj'
insert image description here

insert image description here

Guess you like

Origin blog.csdn.net/weixin_53791978/article/details/132065608