使用 axios 套件 post form-data 範例函式:
const axios = require('axios').create({
withCredentials: true
})
function postFormData (uri, data) {
const formData = new FormData()
Object.keys(data).forEach(key => {
formData.append(key, data[key])
})
const request = axios.post(uri, formData)
.then(r => r.data)
.catch(function (e) {
console.error(e)
})
return request
}
postFormData ('/1/post/', { name: 'TEST' })
.then(r => {
// ....
})