当前位置: 首页 > news >正文

威联通怎么建设网站企业文化墙创意设计图

威联通怎么建设网站,企业文化墙创意设计图,低价网站建设方案,专业团队p图准备工作 安装依赖 npm init -y npm i koakoa 文档#xff1a;https://koajs.cn/# koa 中不能用回调的方式来实现#xff0c;因为 async 函数执行的时候不会等待回调完成 app.use(async (ctx, next) {console.log(ctx.path, ctx.method);if (ctx.path /login…准备工作 安装依赖 npm init -y npm i koakoa 文档https://koajs.cn/# koa 中不能用回调的方式来实现因为 async 函数执行的时候不会等待回调完成 app.use(async (ctx, next) {console.log(ctx.path, ctx.method);if (ctx.path /login ctx.method POST) {const arr [];ctx.req.on(data, function (chunk) {arr.push(chunk);});ctx.req.on(end, function () {const result Buffer.concat(arr).toString();console.log(result----, result);ctx.body result;});} else {next();} });koa 中所有的异步都必须是 promise只有 promise 才有等待效果必须所有的 next 方法前需要有 await、return 否则没有等待效果 app.use(async (ctx, next) {console.log(ctx.path, ctx.method);if (ctx.path /login ctx.method POST) {await new Promise((resolve, reject) {const arr [];ctx.req.on(data, function (chunk) {arr.push(chunk);});ctx.req.on(end, function () {const result Buffer.concat(arr).toString();console.log(result----, result);ctx.body result;resolve();});});} else {await next();} });实现一个表单提交功能 server.js const Koa require(koa);const app new Koa();app.use((ctx, next) {// 路径是 /login get 方式// ctx 包含了 request response req resconsole.log(ctx.path, ctx.method);if (ctx.path /login ctx.method GET) {ctx.body form action/login methodpost用户名input typetext nameusername/br/密码input typepassword namepassword/br/button提交/button/form;} else {return next();} });app.use(async (ctx, next) {console.log(ctx.path, ctx.method);if (ctx.path /login ctx.method POST) {await new Promise((resolve, reject) {const arr [];ctx.req.on(data, function (chunk) {arr.push(chunk);});ctx.req.on(end, function () {const result Buffer.concat(arr).toString();console.log(result----, result);ctx.body result;resolve();});});} else {await next();} });app.on(error, function (err) {console.log(error-----, err); });app.listen(3000);启动服务访问 http://localhost:3000/login nodemon server.js输入账号密码点击提交 koa-bodyparser 下面使用 koa-bodyparser 简化逻辑安装 koa-bodyparserhttps://www.npmjs.com/package/koa-bodyparser npm i koa-bodyparser用法 const Koa require(koa); const bodyParser require(koa-bodyparser);const app new Koa(); app.use(bodyParser());app.use(async ctx {// the parsed body will store in ctx.request.body// if nothing was parsed, body will be an empty object {}ctx.body ctx.request.body; });业务里添加逻辑 const Koa require(koa); const bodyParser require(koa-bodyparser); const app new Koa(); app.use(bodyParser());app.use((ctx, next) {// 路径是 /login get 方式// ctx 包含了 request response req resconsole.log(ctx.path, ctx.method);if (ctx.path /login ctx.method GET) {ctx.body form action/login methodpost用户名input typetext nameusername/br/密码input typepassword namepassword/br/button提交/button/form;} else {return next();} });app.use(async (ctx, next) {console.log(ctx.path, ctx.method);if (ctx.path /login ctx.method POST) {ctx.body ctx.request.body;} else {await next();} });app.on(error, function (err) {console.log(error-----, err); });app.listen(3000);效果也是一样的 下面自己实现 koa-bodyparser const querystring require(querystring); console.log(使用的是 kaimo-koa-bodyparser 中间件); // 中间件的功能可以扩展属性、方法 module.exports function () {return async (ctx, next) {await new Promise((resolve, reject) {const arr [];ctx.req.on(data, function (chunk) {arr.push(chunk);});ctx.req.on(end, function () {if (ctx.get(content-type) application/x-www-form-urlencoded) {const result Buffer.concat(arr).toString();console.log(kaimo-koa-bodyparser-result----, result);ctx.request.body querystring.parse(result);}resolve();});});await next(); // 完成后需要继续向下执行}; };将业务代码的引用自己实现的 // 使用自己实现的 koa-bodyparser const bodyParser require(./kaimo-koa-bodyparser);启动服务效果一样
http://wiki.neutronadmin.com/news/35064/

相关文章:

  • 做语音聊天网站要多少钱三亚网站运营托管介绍
  • 怎么查询一个网站有没有做竞价swoole wordpress
  • 描述photoshop在网站建设中的作用与特点.设计师兼职平台
  • 网站权重收录官网推广方案seo
  • 建设厅教育培训网站小程序定制开发要多少钱
  • 郑州网站建设找三牛wordpress 3.8 问题
  • wordpress网站安全性发布产品的免费平台有哪些
  • 广州seo网站多少钱基于MVC网站建设课程设计报告
  • 网站吸引人的功能石家庄大型网络公司
  • 网站大全官网专门做鞋子的网站
  • 智慧团建信息系统网站登录手把手教你搭建自己的网站
  • dns解析失败登录不了网站WordPress中文企业免费主题
  • 中山网页建站模板深圳调查公司哪家好
  • 一家网站建设公司需要什么资质泰兴企业网站建设
  • 奢华网站模板网络架构设计方案
  • html5网站用什么软件做视频官方网站
  • 天津建设网站c2成绩查询易做文学网站的logo
  • 上海企业网站黄页网站模板怎么使用教程
  • 做盘石信用认证网站网站建设与管理找工作
  • 视频网站公共关系怎么做网站设计与网页制作模板
  • 建立网站网站建设的硬件支持
  • 梅州建设公司网站秦皇岛做网站的公司
  • 数据网站建设深圳市住建局工程交易服务网
  • 电子元件做的比较好的网站合肥建设厅官方网站
  • 做网站对于不同的分辨率西安建设科技专修学院官方网站
  • 做网站公司联系方式页面zh cn wordpress
  • 营销型网站的三元素网站建设深圳龙华
  • 企业网站推广哪个公司好中山网站开发招聘
  • 营销型网站建设与网盟空间中国网站
  • c#网站开发模板简历免费模板