From c61e9ea35656edf1c92606951f22c7887f1decfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=93=E6=96=87=E8=90=8D?= <1721629528@qq.com> Date: Sat, 26 Mar 2022 11:41:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BA=863=E6=9C=8810=20?= =?UTF-8?q?=EF=BC=8C3=E6=9C=8811=E7=9A=84=E4=BD=9C=E4=B8=9A=E7=AC=94?= =?UTF-8?q?=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo01.js" | 34 +++++++ .../index.html" | 0 .../nunjucks.js" | 16 ++++ .../promise.js" | 43 +++++++++ .../promisedemo.js" | 88 +++++++++++++++++++ .../url.js" | 20 +++++ 6 files changed, 201 insertions(+) create mode 100644 "\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-10-\344\275\234\344\270\232/demo01.js" create mode 100644 "\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-10-\344\275\234\344\270\232/index.html" create mode 100644 "\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-10-\344\275\234\344\270\232/nunjucks.js" create mode 100644 "\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-11-\344\275\234\344\270\232/promise.js" create mode 100644 "\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-11-\344\275\234\344\270\232/promisedemo.js" create mode 100644 "\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-11-\344\275\234\344\270\232/url.js" diff --git "a/\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-10-\344\275\234\344\270\232/demo01.js" "b/\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-10-\344\275\234\344\270\232/demo01.js" new file mode 100644 index 0000000..eba227d --- /dev/null +++ "b/\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-10-\344\275\234\344\270\232/demo01.js" @@ -0,0 +1,34 @@ +/**项目介绍:thinknode + * 采用: + * 异步网络编程,具有具有高并发,高可靠行,自建常驻内存的session机制,传统session 文件读取,mvc设计模式, + * nunjucks 模板引擎,简洁高效,具有高并发高可靠性 + * + * 项目预览: + * + * 网站目录结构: + * + * 没有固定模式,但尽可能规整 + * + * untils:工具类目录 + * + * home:前端 + * controller + * css + * imgs + * views + * + * admin:后端 + * controller + * css + * imgs + * views + * + * config:配置文件 + * db.js + * + * app.js 入口文件 + * + * 什么是mvc:首先mvc 是一种设计模式,不限语言,回顾计算机基础知识:计算机如何工作,cpu 指挥 硬盘等文件操作, + * + * mvc 也类似,c 表示业务的指挥者,controller ,model 就好比计算机中的其余各个模块,听从 cpu的指挥 +*/ \ No newline at end of file diff --git "a/\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-10-\344\275\234\344\270\232/index.html" "b/\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-10-\344\275\234\344\270\232/index.html" new file mode 100644 index 0000000..e69de29 diff --git "a/\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-10-\344\275\234\344\270\232/nunjucks.js" "b/\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-10-\344\275\234\344\270\232/nunjucks.js" new file mode 100644 index 0000000..8dd9858 --- /dev/null +++ "b/\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-10-\344\275\234\344\270\232/nunjucks.js" @@ -0,0 +1,16 @@ +//nunjucks:功能强大的JavaScript专用模板引擎 +// 1.功能丰富且强大,并支持块级继承(block inheritance)、自动转义、宏(macro)、异步控制等等。完美继承了 jinja2 的衣钵。 +// 2.快速 & 干练 并且高效。运行时代码经过压缩之后只有 8K 大小, 可在浏览器端执行预编译模板。 +// 3.可扩展 性超强,用户可以自定义过滤器(filter)和扩展模块。 +// 4. 到处 可运行,无论是 node 还是任何浏览器都支持,并且还可以预编译模板。 + +var app = express(); + +nunjucks.configure('views', { + autoescape: true, + express: app +}); + +app.get('/', function(req, res) { + res.render('index.html'); +}); \ No newline at end of file diff --git "a/\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-11-\344\275\234\344\270\232/promise.js" "b/\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-11-\344\275\234\344\270\232/promise.js" new file mode 100644 index 0000000..f1952c5 --- /dev/null +++ "b/\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-11-\344\275\234\344\270\232/promise.js" @@ -0,0 +1,43 @@ +//笔记部分 + +// es6中async 函数 和 await的用法: + // 1.async作为一个关键字放到函数前面 + // 任何一个async函数都会隐式返回一个promise + + // 2.await关键字只能在使用async定义的函数中使用 + // await后面可以直接跟一个 Promise实例对象 +// await函数不能单独使用必须配合async使用 + +//async/await优点: + //让异步代码看起来、表现起来更像同步代码 ,简化异步操作 + +//fetch + +// Fetch API是新的ajax解决方案 Fetch会返回Promise +// fetch不是ajax的进一步封装,而是原生js,没有使用XMLHttpRequest对象 +// 方法:fetch(url, options).then() + +// axios: + +// 是一个基于Promise 用于浏览器和 nodejs 的 HTTP 客户端,本质上也是对原生Ajax的封装,只不过它是Promise的实现版本它支持: + + // 1.支持浏览器和node.js + // 2.支持promise + // 3.能拦截请求和响应 + // 4.自动转换JSON数据 + // 5.能转换请求和响应数据 + +// axios基础用法: +// 如果是get和 delete请求传递参数时 + + // 1.如果通过传统的url 以 ? 的形式传递参数 + // 2.如果通过restful 形式传递参数 + // 3.也可以通过params 形式传递参数 + +//通过 reslove 变为成功状态,reject 变为失败状态, +//里面有个 function (resolve,reject) +// resolve 和 reject 是一个函数,可以传值; +// promse ,通过then 取得 resolve 或是 reject的值; +// 出来 await/async ,promise 前面加上一个 await,就不需要 then来取值了,直接把 resolve 或是 reject的值返回; +// await 必须要在 async 函数内使用; +// await + promise 函数内部,变成同步代码,但是其余代码是 异步的 \ No newline at end of file diff --git "a/\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-11-\344\275\234\344\270\232/promisedemo.js" "b/\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-11-\344\275\234\344\270\232/promisedemo.js" new file mode 100644 index 0000000..32bc9f0 --- /dev/null +++ "b/\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-11-\344\275\234\344\270\232/promisedemo.js" @@ -0,0 +1,88 @@ +let fs = require('fs'); + +let fileName = './1.txt'; + +fs.exists(fileName, function (result) { + + if (result) { + fs.readFile(fileName, function (err, data) { + console.log(data.toString()); + }) + } + +}); + + +let promise = new Promise(function (resolve, reject) { + + setTimeout(function () { + resolve('我是成功状态');//把 promise状态改变 + + }, 200); + +}); + +// console.log(promise); + +// promise.then(function(x){ +// console.log('我是成功的输出:'+x); +// },function(y){ +// console.log('我是失败的输出:'+y); +// }) + + +function promiseFun() { + + let promise = new Promise(function (resolve, reject) { + + setTimeout(function () { + resolve('我是成功状态');//把 promise状态改变 + + }, 200); + + }); + return promise; +} +async function demo() { + + let result = await promiseFun(); + + console.log(result); + + console.log('我是函数内部的最下面1'); + + console.log('我是函数内部的最下面2'); + + console.log('我是函数内部的最下面3'); + +} + + + +// demo(); + +// console.log('我是外层的下部输出'); + + +function readFileByPromise(filename){ + + return new Promise(function(resolve,reject){ + fs.readFile(fileName,function(err,data){ + if(err){ + reject(err.message); + }else{ + resolve(data.toString()); + } + }) + }) + +} + +async function handleFile(fileName){ + + let content = await readFileByPromise(fileName); + + console.log(content); +} + +handleFile('./1.txt'); \ No newline at end of file diff --git "a/\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-11-\344\275\234\344\270\232/url.js" "b/\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-11-\344\275\234\344\270\232/url.js" new file mode 100644 index 0000000..c73e9b6 --- /dev/null +++ "b/\346\230\223\346\226\207\350\220\215\347\232\204\344\275\234\344\270\232/2022-03-11-\344\275\234\344\270\232/url.js" @@ -0,0 +1,20 @@ +/** + * url 资源定位: + * 1.静态资源 css img js html... /home/css/1.css + * 2.动态资源,我们简单理解,需要请求数据库的资源 ?front=home&c=index&a=index + * c 是 controller 简写,a action(就是 class 里面function) 的简写, + * 要用到 class,为什么要 class ,不用json 处理, class 有继承 + * url由程序员规定 + * + * 目录结构先完善: + home: + controller + imgs + css + html + admin: + controller + imgs + css + html + */ \ No newline at end of file -- Gitee