Nginx
Nginx
Nginx 命令
nginx -v # 查看 nginx 版本nginx -V # 查看版本和配置选项信息nginx # 启动nginx -s reopen # 重启nginx -s stop # 立即停止nginx -s quit # 等待进程结束后关闭nginx -s reload # 重新加载配置nginx -T # 查看最终配置nginx -t # 测试配置文件是否有语法错误nginx -c <fileName> # 指定配置文件ps aux|grep nginx # 查看进程
Nginx 基本配置
默认配置
# nginx.config# nginx 全局配置 start#user nobody; # 运行用户worker_processes 1; # 并发处理服务,值越大,并发数越多。# 错误日志#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid; ...
Vue 3 + Typescript + Vite2
初始化项目
yarn create vite <project name> --template vue-ts
or
yarn create vite
配置别名
安装 node TS 声明文件
yarn add --dev @types/node
修改 vite.config.ts
// ...import path from 'path' // 此语法有可能导致 idea 报错 TS1259: Module '"path"' can only be default-imported using the 'esModuleInterop' flag, 改成 import path = require('path') 可解决报错// https://vitejs.dev/config/export default defineConfig({ resolve: { alias: { "src": path. ...
VuePress
VuePress
使用
安装
在现有项目中
# 将 VuePress 作为一个本地依赖安装yarn add -D vuepress # 或者:npm install -D vuepress# 新建一个 docs 文件夹mkdir docs# 新建一个 markdown 文件echo '# Hello VuePress!' > docs/README.md
添加 package.json 配置
{ "scripts": { "docs:dev": "vuepress dev docs", "docs:build": "vuepress build docs" }}
命令行运行以下命令开启 dev server
yarn docs:dev # 或者:npm run docs:dev
创建目录
在 docs 中创建相应的文件目录并在其中创建 README.md 文件,如:
.├─ docs│ ├─ ...
Vue组件通信
Vue 组件通信
prop & $emit
使用 :number="number" 为组件传递一个数据
使用 @add="addNumber" 监听自定义事件
<div id="app"> {{ msg }} <Child :number="number" @add="addNumber"></Child></div>
使用 props 接收传递的数据
使用 $emit 触发自定义事件
// 子组件Vue.component('Child', { // 在 button 中监听 click 事件 template: ` <div> <p>{{ number }}</p> <button @click="onClick"> ...
Promise、async
Promise
Promise.resolve() 创建一个成功或失败
Promise.resolve('s');Promise.resolve(new Promise((resolve, reject) => reject())); // error
Promise.reject() 创建一个失败
Promise.reject('错误').then(null, reason => console.log(reason))// 错误
Promise.all() 所有都成功,或者有一个失败
Promise.all([Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)]) .then(values => console.log(values)) // [1, 2, 3]Promise.all([Promise.resolve(1), Promise.reject(2), Promise.reject(3)]) .then(null, reason => c ...
webpack
webpack5
初始化项目
yarn init -y
安装 webpack
yarn add webpack webpack-cli --dev
根目录创建 webpack.config.js 并添加以下内容
module.exports = { mode: 'production',}
在 package.json 添加
"scripts": { "build": "webpack"},
支持部分 IE 浏览器
根目录创建 .browserslistrc 并添加以下内容
[production] # production 环境> 1% # 支持大于 1% 的浏览器ie 9 # 支持 IE9[modern]last 1 chrome version # chrome 最新的一个个版本last 1 firefox version # firefox 最新的一个个版本[ssr]node 12
用 babel 打包 js
安装 babel 相关依赖
ya ...
HTTP
HTTP
TCP/IP
通常使用的网络(包括互联网)是在 TCP/IP 协议族的基础上运作的。而 HTTP 属于它内部的一个子集。
TCP/IP 协议族里重要的一点就是分层。TCP/IP 协议族按层分别为四层:应用层、传输层、网络层和数据链路层。
应用层决定了向用户提供应用服务时通信的活动。HTTP 协议处于该层。
传输层对上层应用层,提供处于网络连接中的两台计算机之间的数据传输。
网络层用来处理在网路上流动的数据包。该层规定了通过怎样的路径(所谓的传输路线)到达对方计算机,并把数据包传送给对方。
数据链路层用来处理连接网络的硬件部分。
利用 TCP/IP 协议族进行网络通信时,会通过分层顺序与对方进行通信。发送端从应用层往下走,接收端则从链路层往上走。
发送端在层与层之间传输数据时,每经过一层时必定会被打上一个该层所属的首部信息。反之,接收端在层与层传输数据时,每经过一层时会把对应的首部消去。
这种把数据信息包装起来的做法称为封装(encapsulate)。
IP 协议
按层次分,IP(Internet Protocol)网际协议位于网络层。
IP 协议的作用是把各种数 ...
Underscore
Underscore 基本用法
Collections
map() 对集合每一项进行一些操作,返回新数组
_.map([1, 2, 3, 4, 5], i => i+1) // [2, 3, 4, 5, 6]
each() 遍历集合类似map
_.each([1, 2, 3, 4, 5], i => console.log(i+1)) // 2 3 4 5 6
reduce() 对集合进行操作且累计并返回结果,第三个参数为操作初始值
_.reduce([1, 2 ,3], (memo, num) => memo + num, 0) // 6_.reduce([1, 2 ,3], (memo, num) => memo + num, 10) // 16_.reduce([1, 2 ,3], (memo, num) => memo * num, 1) // 6_.reduce([1, 2 ,3], (memo, num) => memo * num, 10) // 60
shuffle() 打乱集合顺序
const ...
mongoDB
mongoDB
操作数据库
创建、切换
use 数据库名
切换数据库,如不存在就创建一个新的数据库。
use test
删除
db.dropDatabase()
删除数据库
查看
show dbs
查看当前的数据库
操作集合
查看集合
show tables
查看当前数据库中的集合
创建集合
db.集合名.insert()
向集合里插入文档,如集合不存在创建一个集合
删除集合
db.集合名.drop()
删除当前数据库中的集合
操作文档
查看集合里的文档
db.集合名.find()
查看集合中的全部文档
查看第一个文档
db.集合名.find
查看某个文档
db.集合名.find({查询条件})
查询符合条件的文档
db.集合名.find({content: /jay/})
查询 content 包含 ‘jay’ 的文档
db.集合名.find({content: /^jay/})
查询 content 以 ‘jay’ 开头的文档
db.集合名.find({content: / ...
关于 JavaScript 中 this 对象
this
this是在运行时调用的,它的值取决于函数的调用位置。
调用方式
独立函数中的 this
在全局函数中,this 指向全局对象 window。
var n = 1function example () { this === window // true console.log(this.n)}example() // 1
严格模式下,this 的值为 undefined。
var n = 1function example () { 'use strict' this === undefined // true console.log(this.n)}example() // TypeError: this is undefined
但只在严格模式下调用函数不会影响 this 的值
var n = 1function example () { this === window // true console.log(this.n)}(function () { ...