koa前后端连接的中间件:fetch,

6-1.2.3:koa 的使用,在设置config里proxy之后,后台的get方法确实是成功传到前台了的
*******************到底是怎么传的***************
首先后台页面已经搭建好,前台转发设置好,前台引入执行函数,中间的部分怎么弄 的?
引入两个模块
import 'whatwg-fetch'
import 'es6-promise'
export function postData(){//这个定义的执行函数
var result =fetch('/api/post',{  //这个是定义的前后台连接的接口
method:"POST",
credentials:'include',
headers:{                   //这是固定的写法
'Accept':'application/json,text/plain,*/*',
'Content-Type':'application/x-www-form-urlencoded'  //这个在转换body的格式
},
body:"a=100&b=200"         //这个是传输的内容,却没有显示在页面上--请求已经发往后台
});
result.then(res=>{
console.log(144)
console.log(res.text())
return res.text()
}).then(json=>{
console.log(json,147)  //这两个都执行了的--json代表后台页面的数据-这个接口
})
}
**********能够从后台获取数据,如何向后台传递数据呢?
fetch应该是个中间件,从前台拿到数据,再传递给后台,跟axios差不多;

你可能感兴趣的:(koa前后端连接的中间件:fetch,)