首页 > 解决方案 > 使用 Axios 在 JSON-SERVER 上将数据作为新资源发布?

问题描述

我正在尝试将数据作为新资源发布到服务器上,该怎么做?

将数据作为资源发布的代码:

const postData = async () => {
    const response = await axios.post('http://localhost:3000/', { newResource: [{id:2,name:'b'}] });
    response.then((response)=>{
        console.log(response.data)
    })
};

添加资源之前的 db.json:

{
    "oldResource": [
        {
            "id": 1,
            "name": "a",
        }
    ]
}

添加资源后我想要db.json:

{
    "oldResource": [
        {
            "id": 1,
            "name": "a",
        }
    ],
    "newResource": [
        {
            "id": 2,
            "name": "b",
        }
    ]
}

问题 它说 404 未找到。

什么是磨损或没有办法做到这一点?请帮忙!

标签: jsonreactjsapiaxiosjson-server

解决方案


推荐阅读