Convert JS Object to form data

前端 未结 18 1905
孤街浪徒
孤街浪徒 2020-11-29 17:22

How can I can convert my JS Object to FormData?

The reason why I want to do this is, I have an object that I constructed out of the ~100 form field valu

18条回答
  •  没有蜡笔的小新
    2020-11-29 17:33

    Try obj2fd => https://www.npmjs.com/package/obj2fd

    import obj2fd from 'obj2fd'
    
    let data = {a:1, b:2, c:{ca:1}};
    let dataWithFormData = obj2fd(data);
    //result => [a=>1, b=>2, c=>[ca=>1]]
    

提交回复
热议问题