一、get请求 *gg为get,pp为post
代码截图:
app/router.js
app/controller/gg.js
使用postman,输入地址,send即可,得到数据就是成功了,鼓掌!
成功截图!
二、post请求
也是截图:
app/router.js
app/controller/pp.js
成功截图!
但是你没有成功截图,hh 使用egg调用POST请求时,浏览器会触发405报错
需要使用egg-cors插件
npm i egg-cors –save
设置config/config.default.js
里面的链接写你自己的hh
设置config/plugin.js
酱样子
就可以成功了-_-
三、jsonp请求
app/router.js
app/demo/count.json
app/controller/demo.js
成功~
参考文章: https://www.jianshu.com/p/45c9cb7c4a54 上面更为详细。