跨域问题的解决方案
1.jsonp的方法
//ajax封装的jsonp,jsonp本质上是通过script标签的src属性解决的跨域问题,只能解决get类型的请求
$.ajax({
url: 'http://127.0.0.1:3000/fruits',
dataType: 'jsonp'
}).done(res => {
console.log(res)
})
2.通过设置响应头,在后端解决
router.get('/fruits', ctx => {
ctx.set('Access-Control-Allow-Origin', '*')
ctx.body = dataList
})