扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

axios怎么发送json数组

扬州沐宇科技
2024-01-11 13:18:25
axios, json

使用axios发送JSON数组的方法如下:

import axios from 'axios';

const data = [
  { name: 'John', age: 25 },
  { name: 'Jane', age: 30 },
  { name: 'Bob', age: 35 }
];

axios.post('/api/endpoint', data)
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error(error);
  });

这里的data是一个JSON数组,通过axios.post方法发送到指定的API端点。在服务器端,你可以使用相应的框架/库(如Express)来解析和处理接收到的JSON数组数据。

扫码添加客服微信