《Node.js+Vue.js+MangoDB全棧開發實戰》已出版

邹琼俊發表於2024-05-01

《Node.js+Vue.js+MangoDB全棧開發實戰》

圖書購買地址:

京東:《Node.js+Vue.js+MangoDB全棧開發實戰》

噹噹:《Node.js+Vue.js+MangoDB全棧開發實戰》

天貓:《Node.js+Vue.js+MangoDB全棧開發實戰》

隨書原始碼下載地址:

連結:https://pan.baidu.com/s/1DQYgPZLmtJCIuDXs8gub_w?pwd=1127
提取碼:1127

課件下載地址:

連結:https://pan.baidu.com/s/1M36y1xu-gIUidDxw38GlBg
提取碼:1988

隨書目錄

目 錄

第1章 Node.js和TypeScript基礎·································································· 1

1.1 Node.js開發概述······································································································· 1

1.1.1 為什麼要學習Node.js························································································ 1

1.1.2 什麼是Node.js································································································· 2

1.1.3 Node.js特點···································································································· 3

1.1.4 var、let和const的區別······················································································ 3

1.1.5 開發工具········································································································ 4

1.2 Node執行環境搭建···································································································· 5

1.2.1 Node.js執行環境安裝························································································ 5

1.2.2 Node環境安裝失敗解決辦法··············································································· 6

1.2.3 程式碼有無分號的問題························································································· 6

1.3 Node.js快速入門······································································································· 7

1.3.1 Node.js的組成································································································· 7

1.3.2 Node.js基礎語法······························································································ 7

1.3.3 Node.js全域性物件global······················································································ 7

1.4 nvm簡介、安裝、使用······························································································· 8

1.5 VS Code的使用········································································································· 9

1.5.1 忽略node_module目錄····················································································· 10

1.5.2 安裝VS Code外掛·························································································· 10

1.5.3 開啟並執行專案······························································································ 12

1.5.4 VS Code配置································································································· 14

1.5.5 搜尋············································································································· 15

第2章 模組載入及第三方包········································································· 17

2.1 Node.js模組化開發··································································································· 17

2.1.1 JavaScript開發弊端·························································································· 17

2.1.2 模組化·········································································································· 18

2.1.3 Node.js中模組化開發規範················································································· 18

2.1.4 exports和module.exports的區別········································································· 20

2.1.5 require優先從快取載入····················································································· 21

2.2 系統模組················································································································ 22

2.2.1 什麼是系統模組······························································································ 22

2.2.2 系統模組fs檔案操作······················································································· 22

2.2.3 系統模組path路徑操作···················································································· 24

2.2.4 相對路徑VS絕對路徑····················································································· 24

2.3 第三方模組············································································································· 25

2.3.1 什麼是第三方模組··························································································· 25

2.3.2 獲取第三方模組······························································································ 25

2.3.3 npm············································································································· 25

2.3.4 yarn············································································································· 26

2.3.5 yarn和npm的區別·························································································· 27

2.3.6 第三方模組nrm······························································································ 28

2.3.7 第三方模組nodemon························································································ 29

2.3.8 第三方模組 gulp····························································································· 29

2.3.9 npx·············································································································· 36

2.4 package.json檔案······································································································ 37

2.4.1 node_modules目錄的問題·················································································· 37

2.4.2 package.json檔案的作用···················································································· 38

2.4.3 專案依賴和開發依賴························································································ 38

2.4.4 package.json檔案各個選項含義··········································································· 38

2.4.5 package-lock.json檔案的作用·············································································· 40

2.4.6 yarn.lock的作用······························································································ 40

2.5 Node.js中模組的載入機制·························································································· 41

2.5.1 模組查詢規則:當模組擁有路徑但沒有字尾時······················································· 41

2.5.2 模組查詢規則:當模組沒有路徑且沒有字尾時······················································· 41

第3章 HTTP及Node非同步程式設計···································································· 44

3.1 C/S、B/S軟體體系結構分析······················································································· 44

3.2 伺服器端基礎概念···································································································· 45

3.2.1 網站的組成···································································································· 45

3.2.2 網站伺服器···································································································· 46

3.2.3 IP地址········································································································· 46

3.2.4 域名············································································································· 47

3.2.5 埠············································································································· 48

3.2.6 URL············································································································· 49

3.2.7 客戶端和伺服器端··························································································· 49

3.3 建立web伺服器······································································································ 49

3.4 HTTP協議·············································································································· 51

3.4.1 HTTP協議的概念··························································································· 51

3.4.2 報文············································································································· 51

3.4.3 請求報文······································································································· 52

3.4.4 響應報文······································································································· 57

3.5 HTTP請求與響應處理······························································································· 58

3.5.1 請求引數······································································································· 58

3.5.2 GET請求引數································································································ 58

3.5.3 POST請求引數······························································································ 59

3.5.4 路由············································································································· 60

3.5.5 靜態資源······································································································· 61

3.5.6 動態資源······································································································· 62

3.5.7 客戶端請求方式······························································································ 63

3.6 Node.js非同步程式設計······································································································ 64

3.6.1 同步API,非同步API························································································ 64

3.6.2 同步API,非同步API的區別·············································································· 64

3.6.3 回撥函式······································································································· 66

3.6.4 Node.js中的非同步API······················································································· 66

3.6.5 Promise········································································································· 68

3.6.6 非同步函式async和await···················································································· 70

第4章 MongoDB資料庫············································································ 72

4.1 資料庫概述············································································································· 72

4.1.1 為什麼要使用資料庫························································································ 72

4.1.2 什麼是資料庫································································································· 72

4.1.3 MongoDB資料庫相關概念················································································ 73

4.2 MongoDB資料庫環境搭建························································································· 75

4.2.1 MongoDB資料庫下載安裝················································································ 75

4.2.2 啟動MongoDB······························································································· 78

4.3 MongoDB操作········································································································ 78

4.3.1 MongoDB的Shell操作···················································································· 78

4.3.2 MongoDB視覺化軟體······················································································ 83

4.3.3 MongoDB匯入匯出資料··················································································· 85

4.4 MongoDB索引介紹及資料庫命令操作·········································································· 86

4.4.1 建立簡單索引································································································· 86

4.4.2 唯一索引······································································································· 88

4.4.3 刪除重複值···································································································· 88

4.4.4 Hint············································································································· 88

4.4.5 Expain·········································································································· 88

4.4.6 索引管理······································································································· 90

4.5 MongoDB備份與恢復······························································································· 91

4.5.1 MongoDB資料庫備份······················································································ 91

4.5.2 MongoDB資料庫恢復······················································································ 91

4.6 Mongoose資料庫連線······························································································· 93

4.7 Mongoose增刪改查操作···························································································· 93

4.7.1 建立資料庫···································································································· 94

4.7.2 建立集合······································································································· 95

4.7.3 建立文件······································································································· 95

4.7.4 查詢文件······································································································· 96

4.7.5 刪除文件····································································································· 101

4.7.6 更新文件····································································································· 101

4.7.7 mongoose驗證······························································································ 102

4.7.8 集合關聯····································································································· 103

第5章 art-template模板引擎······································································ 106

5.1 模板引擎的基礎概念······························································································· 106

5.1.1 模板引擎····································································································· 106

5.1.2 art-template簡介····························································································· 107

5.2 模板引擎語法········································································································ 110

5.2.1 輸出··········································································································· 110

5.2.2 原文輸出····································································································· 110

5.2.3 條件判斷····································································································· 110

5.2.4 迴圈··········································································································· 110

5.2.5 子模板········································································································ 111

5.2.6 模板繼承····································································································· 111

5.2.7 模板配置····································································································· 112

5.3 案例——使用者管理·································································································· 113

5.3.1 案例介紹····································································································· 113

5.3.2 操作步驟····································································································· 115

第6章 Express框架················································································ 125

6.1 Express框架簡介···································································································· 125

6.1.1 Express框架是什麼························································································ 125

6.1.2 Express框架特性··························································································· 125

6.2 中介軟體················································································································· 126

6.2.1 什麼是中介軟體······························································································· 126

6.2.2 app.use中介軟體用法························································································ 127

6.2.3 中介軟體應用·································································································· 128

6.2.4 錯誤處理中介軟體···························································································· 129

6.2.5 捕獲異常····································································································· 130

6.3 Express請求處理···································································································· 131

6.3.1 構建路由····································································································· 131

6.3.2 構建模組化路由···························································································· 132

6.3.3 GET引數的獲取···························································································· 132

6.3.4 POST引數的獲取·························································································· 133

6.3.5 Express路由引數··························································································· 134

6.3.6 靜態資源處理······························································································· 135

6.4 express-art-template模板引擎······················································································ 135

6.5 express-session········································································································ 136

6.5.1 Session簡單介紹··························································································· 136

6.5.2 express-session的使用····················································································· 136

6.5.3 express-session 的常用引數·············································································· 137

第7章 TypeScript介紹············································································ 138

7.1 TypeScript基礎······································································································· 138

7.1.1 TypeScript簡介····························································································· 138

7.1.2 TypeScript的特點·························································································· 139

7.1.3 安裝TypeScript····························································································· 139

7.1.4 ts和js的區別······························································································· 140

7.1.5 編寫TS程式································································································ 140

7.1.6 手動編譯程式碼······························································································· 141

7.1.7 VS Code自動編譯························································································· 142

7.1.8 型別註解····································································································· 143

7.1.9 vite快速建立ts開發環境················································································· 144

7.2 基礎型別·············································································································· 145

7.2.1 布林值········································································································ 145

7.2.2 數字··········································································································· 146

7.2.3 字串········································································································ 146

7.2.4 undefined和null···························································································· 146

7.2.5 陣列··········································································································· 147

7.2.6 元組Tuple···································································································· 147

7.2.7 列舉··········································································································· 147

7.2.8 any············································································································· 148

7.2.9 void············································································································ 148

7.2.10 Never········································································································ 149

7.2.11 Object········································································································ 149

7.2.12 聯合型別···································································································· 149

7.2.13 型別斷言···································································································· 150

7.2.14 型別推斷···································································································· 150

7.3 介面···················································································································· 151

7.3.1 介面初探····································································································· 151

7.3.2 可選屬性?···································································································· 151

7.3.3 只讀屬性readonly·························································································· 152

7.3.4 函式型別····································································································· 152

7.3.5 類型別········································································································ 153

7.4 類······················································································································· 154

7.4.1 基本示例····································································································· 154

7.4.2 繼承··········································································································· 154

7.4.3 公共,私有與受保護的修飾符·········································································· 157

7.4.4 readonly 修飾符···························································································· 158

7.4.5 存取器········································································································ 158

7.4.6 靜態屬性····································································································· 159

7.4.7 抽象類········································································································ 160

7.5 函式···················································································································· 160

7.5.1 基本示例····································································································· 160

7.5.2 函式型別····································································································· 161

7.5.3 可選引數和預設引數······················································································ 161

7.5.4 剩餘引數····································································································· 161

7.5.5 函式過載····································································································· 162

7.6 泛型···················································································································· 162

7.6.1 泛型引入····································································································· 163

7.6.2 使用函式泛型······························································································· 163

7.6.3 多個泛型引數的函式······················································································ 163

7.6.4 泛型介面····································································································· 163

7.6.5 泛型類········································································································ 164

7.6.6 泛型約束····································································································· 165

7.7 宣告檔案和內建物件······························································································· 165

7.7.1 宣告檔案····································································································· 165

7.7.2 內建物件····································································································· 166

第8章 文章管理系統··············································································· 168

8.1 專案環境搭建········································································································ 168

8.1.1 專案介紹····································································································· 168

8.1.2 專案框架搭建······························································································· 169

8.2 專案功能實現········································································································ 176

8.2.1 登入··········································································································· 176

8.2.2 文章管理····································································································· 191

8.2.3 使用者管理····································································································· 203

8.2.4 網站首頁文章展示························································································· 207

8.2.5 文章評論····································································································· 208

8.2.6 訪問許可權控制······························································································· 210

8.3 專案原始碼和執行····································································································· 211

第9章 後臺管理系統··············································································· 213

9.1 專案介紹·············································································································· 213

9.1.1 專案介紹····································································································· 213

9.1.2 技術選型····································································································· 215

9.2 專案搭建·············································································································· 216

9.3 後端專案搭建········································································································ 217

9.3.1 搭建node web伺服器專案··············································································· 217

9.3.2 資料庫初始化······························································································· 226

9.3.3 啟動web伺服器···························································································· 227

9.3.4 介面測試····································································································· 227

9.4 前端專案搭建········································································································ 228

9.4.1 基礎目錄結構構建························································································· 228

9.4.2 配置pinia····································································································· 232

9.4.3 準備路由環境······························································································· 234

9.4.4 封裝介面請求······························································································· 234

9.4.5 搭建主介面·································································································· 237

9.4.6 配置路由····································································································· 243

9.4.7 構建系統後臺首頁························································································· 246

9.4.8 使用者列表····································································································· 248

9.4.9 新增/編輯使用者······························································································ 253

9.4.10 配置代理···································································································· 258

9.5 專案執行·············································································································· 258

相關文章