在axios中使用post提交表单数据,可以通过以下步骤实现:
import axios from 'axios';
axios.post('https://example.com/api/form-submit', {
name: 'John Doe',
email: 'johndoe@example.com',
message: 'Hello, World!'
})
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});
在上面的示例中,我们使用了post方法向https://example.com/api/form-submit
地址提交了一个包含name、email和message字段的表单数据。提交成功后,我们打印了返回的数据,如果请求失败,我们打印了错误信息。
这样就可以使用axios提交表单数据了。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:php怎么提交表单数据到数据库