koa2 pug路由新增備忘方便自查

2021-08-19 02:28:07 字數 724 閱讀 7079

用koa2-generator 建立專案後,用pug做頁面展現,配置路由,將頁面簡單串起來,可以互相跳轉訪問。

路由配置步驟:

1./views/資料夾下新建乙個pug,比如test.pug

2./routes/ 資料夾下新建js檔案,如:test.js

const

router

=require

('koa-router'

)()

router

.prefix

('/test')

module

.exports

=router

router

.get

('/test'

, async

(ctx

, next

) =>

] })

})1)在檔案頭部引入test.js路由:

const

test

=require

('./routes/test'

)2)正文中間使用路由:

// routes

.use

(test

.routes

(),

test

.allowedmethods

()) a

(href

="/test"

) 測試頁面

6.執行專案,完成。

koa2 mysql 事務 koa2整合mysql

引入mysql包 npm install mysql 封裝mysql 建立mysql.js檔案放在utils 工具包 中 使用pool連線池 mysql.js 封裝mysql const mysql require mysql let pools 連線池 let query sql,callback...

Koa2基礎學習

01 環境準備 安裝搭建專案的開發環境 02 中介軟體用法 講解 koa2 中介軟體的用法及如何開發中介軟體 03 路由koa router 04 post get請求 常見請求方式處理 05 分層 梳理 漸近於 mvc 分層模式 06 檢視nunjucks koa 預設支援的模板引擎 07 處理靜...

koa2入門學習

koa模組 koa route 路由 route.get 路徑 路由函式 koa static 靜態資源載入 const serve 路徑 koa compose 中介軟體合成模組 koa body 提取表單post請求鍵值對,處理上傳檔案 上下文context的response和request c...