13KOA JSONP

作者: 帶頭二哥 | 来源:发表于2020-01-07 01:44 被阅读0次

JSONP

安装 JSONP 中间件

npm install koa-jsonp --save

使用中间件

// 引入 koa 模块
const Koa = require('koa')
// 创建 koa 应用
const app = new Koa()

// 引入中间件
const jsonp = require('koa-jsonp')

// 应用中间件
app.use(jsonp())

// 处理请求
app.use( async ctx => {
    let data = {
        success: true,
        data: {
            txt:"aaa",
            msg:"bb"
        }
    }
    ctx.body = data
})

// 启动应用
app.listen(3000)

相关文章

网友评论

    本文标题:13KOA JSONP

    本文链接:https://www.haomeiwen.com/subject/qhdhactx.html