我需要使用javascript对象数组将数据插入为多行。
props.email包含一个数组,例如
props.email = [
{email: 'najathi@email.com', name: 'najathi'},
{email: 'naharni@email.com', name: 'naharni'},
]
axios.post('/create-email.php', props.email, {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
})
.then(response => {
console.log(response);
})
.catch(error => {
console.log(error);
});
答案 0 :(得分:1)
尝试,
const payload = {
email:[
{email: 'najathi@email.com', name: 'najathi'},
{email: 'naharni@email.com', name: 'naharni'},
]
}
axios.post('/create-email.php', payload, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
}
})
.then(response => {
console.log(response.data);
})
.catch(err => {
console.log(err);
})