1.Expressä¸Koaèç³»ä¸åºå«
2.å¦ä½ç ´è§£ devexpress
Expressä¸Koaèç³»ä¸åºå«
Expressä¸Koaçèç³»
ExpressåKoaé½æ¯åºèªTJHolowaychuk大ç¥ä¹æãExpressæ¯ä¸ä¸ªåºäºNode.jså¹³å°çwebåºç¨å¼åæ¡æ¶ãèKoaåæ¯Expressçå级çï¼Koaè¯çä¹åæ£å¼Nodejsæ¨åºasync/awaitè¯æ³ä¹æ¶ï¼Koaéç¨è¿ç§æ°çè¯æ³ç¹æ§ï¼ä¸¢å¼åè°å½æ°ï¼å®ç°äºäºä¸ä¸ªè½»éä¼é çwebå端æ¡æ¶ã两è é½éç¨ä¸é´ä»¶æ¹å¼è¿è¡å¼åï¼å¹¶ä¸ç¸å ³apiåºæ¬æ¯å¤§åå°å¼çã
Expressä¸Koaçåºå«1.ä¸é´ä»¶æ¨¡åExpressçä¸é´ä»¶æ¨¡å为线åï¼èKoaçä¸é´ä»¶æ¨¡å为Uåï¼ä¹å¯ç§°ä¸ºæ´è±æ¨¡åæé ä¸é´ä»¶ã
Express线å模å示ä¾ï¼
constexpress=require("express");constapp=express();constport=;app.use((req,ox指标源码res,next)=>{ res.write("hello");next();});app.use((req,res,next)=>{ res.set("Content-Type","text/html;charset=utf-8");next();});app.use((req,res,next)=>{ res.write("world");res.end();});app.listen();Koaæ´è±æ¨¡å示ä¾ï¼
import*asKoafrom"koa";constapp=newKoa();app.use(async(ctx,next)=>{ ctx.body="hello";awaitnext();ctx.body+="world";});app.use(async(ctx)=>{ ctx.set("Content-Type","text/html;charset=utf-8");});app.listen();å¯ä»¥çå°ï¼Expresså®ç°åæ ·çåè½ï¼è¦æ¯Koaå¤ä¸æ¥ã
2.å¼æ¥æ¹å¼Expresséè¿åè°å®ç°å¼æ¥å½æ°ï¼å¨å¤ä¸ªåè°ãå¤ä¸ªä¸é´ä»¶ä¸åèµ·æ¥å®¹æé»è¾æ··ä¹±ã
//expressåæ³app.get("/test",function(req,res){ fs.readFile("/file1",function(err,data){ if(err){ res.status().send("readfile1error");}fs.readFile("/file2",function(err,data){ if(err){ res.status().send("readfile2error");}res.type("text/plain");res.send(data);});});});Koaéè¿generatoråasync/await使ç¨åæ¥çåæ³æ¥å¤çå¼æ¥ï¼ææ¾å¥½äºcallbackåpromiseã
app.use(async(ctx,next)=>{ awaitnext();vardata=awaitdoReadFile();ctx.response.type="text/plain";ctx.response.body=data;});3.æè·é误Express沿ç¨Node.jsçError-Firstç模å¼ï¼ç¬¬ä¸ä¸ªåæ°æ¯error对象ï¼æ¥æè·é误ã
app.use(function(err,req,res,next){ console.error(err.stack);res.status().send("Somethingbroke!");});Koa使ç¨try/catchçæ¹å¼æ¥æè·é误ã
app.use(async(ctx,next)=>{ try{ awaitnext();}catch(error){ if(error.errorCode){ console.log("æè·å°å¼å¸¸");return(ctx.body=errror.msg);}}});4.ååºæºå¶Expressç«å»ååºï¼res.json/res.sendï¼ï¼ä¸å±ä¸è½åå®ä¹å ¶ä»å¤çã
Koaä¸é´ä»¶æ§è¡å®ä¹åæååºï¼ctx.body=xxxï¼ï¼æ¯ä¸å±é½å¯ä»¥å¯¹ååºè¿è¡èªå·±çå¤ç
æ»ç»åºå«ExpressKoaä¸é´ä»¶æ¨¡å线æ§æ¨¡åæ´è±æ¨¡åå¼æ¥æ¹å¼åºäºåè°å½æ°åºäºasync/awaitæè·é误Error-First模å¼ä½¿ç¨try/catchçæ¹å¼ååºæºå¶ç«å»ååºä¸é´ä»¶æ§è¡å®ä¹åæååºéææ度éæ度é«ï¼èªå¸¦é¨åä¸é´ä»¶éæ度ä½ï¼æ²¡ææç»ä»»ä½ä¸é´ä»¶ä½è ï¼Prayx
å¦ä½ç ´è§£ devexpress
DevExpress .2 ç ´è§£ç (éæ±åå )1ãé¦å æå¼DevExpress .2 ç ´è§£ç (éæ±åå )ææä¾ä¸è½½å®è£ å ï¼
2ãç¶åé»è®¤ä¸é®nextï¼éæ©å®è£ è·¯å¾ï¼
3ãå®è£ å®æ¯å°±å¯ä»¥ä½¿ç¨ï¼è¯¦æ 请çä¸é¢çä¸è½½å¤ã
2024-12-28 10:44
2024-12-28 10:37
2024-12-28 10:29
2024-12-28 10:19
2024-12-28 09:52
2024-12-28 08:41