前端js对象转formData

function paramsToFormData(obj) {
  const formData = new FormData();
  Object.keys(obj).forEach((key) => {
      if (obj[key] instanceof Array) {
        obj[key].forEach((item) => {
          formData.append(key, item);
        });
        return;
      }
      formData.append(key, obj[key]);
    });
  return formData;
}

 

posted @ 2021-06-29 11:37  淋哥  阅读(1542)  评论(0编辑  收藏  举报