将ECONNREFUSED 127.0.0.1:3000与json服务器连接

时间:2018-08-25 14:46:28

标签: javascript json axios

你好,我想用axios创建方法api,然后将数据发布到json-server,但是我正在运行我的代码错误连接,例如mycode:

  const axios = require('axios')
函数addApi(){
   const url = axios.post('http:localhost:3000 / posts,{
                 “ id”:5
                 “ name”:“ lorem”
              })。then((result)=> {
                    console.log('sukses发布到json服务器'+
                    result.data)
                })。catch((err)=> {
                    console.log(err)
                });
  返回网址
}
addApi()
 

并且我运行此代码错误:连接ECONNREFUSED 127.0.0.1:3000

0 个答案:

没有答案