前端
11、Vue3
·3219 字·7 分钟·
loading
·
loading
前端
Vue
Vue3 # 相比vue2的提升 # 性能提升 打包大小减少41% 初次渲染快55%,更新渲染快133% 内存减少43% 源码升级 使用Proxy代替defineProperty实现响应式 重写虚拟DOM的实现和Tree-Shaking 支持TypeScript 可以更好的支持TypeScript 新特性 Composition API 新的内置组件 Vite创建Vue3工程 # Vue3 不推荐使用 vue-cli 来创建(使用vue/cli,要确保版本大于4.5.0),而是使用 Vite。
12、pinia
·2779 字·6 分钟·
loading
·
loading
前端
Vue
pinia # pinia和Vuex的作用是一样的,它也充当的是一个存储数据的作用,存储在pinia的数据允许我们在各个组件中使用。
2、Buffer
·1860 字·4 分钟·
loading
·
loading
前端
NodeJS
NodeJS API
Buffer简介 # JavaScript 语言自身只有字符串数据类型,没有二进制数据类型。
1、TypeScript
·521 字·2 分钟·
loading
·
loading
前端
语言
TypeScript
什么是TypeScript # TypeScript(简称:TS)是 JavaScript 的超集(JS 有的 TS 都有)。
5、nvm
·539 字·2 分钟·
loading
·
loading
前端
NodeJS
NodeJS环境
nvm(Node Version Manager)是Node.js的版本管理器,可以让我们轻松地在不同的Node.js版本之间进行切换。
2、NPM
·1581 字·4 分钟·
loading
·
loading
前端
NodeJS
NodeJS环境
什么是NPM # NPM是随同NodeJS一起安装的包管理工具,能解决NodeJS代码部署上的很多问题,常见的使用场景有以下几种:
2、集成Vue
·2076 字·5 分钟·
loading
·
loading
前端
Electron
使用步骤 # 搭建项目 # 1、安装VueCli,搭建Vue项目 # 找个喜欢的目录,执行以下命令,创建vue项目:
1、入门
·5179 字·11 分钟·
loading
·
loading
前端
Electron
Electron # Electron 基于 Chromium 和 Node.js, 让你可以使用 HTML, CSS 和 JavaScript 构建应用。
8、多进程和多线程
·2449 字·5 分钟·
loading
·
loading
前端
NodeJS
NodeJS API
多进程和多线程的选择 # node.js 目前有两种方案,一种是使用children_process或者cluster开启多进程进行计算,一种是使用worker_thread 开启多线程进行计算
7、http
·2039 字·5 分钟·
loading
·
loading
前端
NodeJS
NodeJS API
Node.js 的 http 模块提供了创建HTTP 服务器和客户端的功能。
HTTP 服务器 # 创建方法 # 使用createServer 创建 # const http = require('http'); // 创建服务对象 const server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello World\n'); }); // 开启监听 3000 端口 server.listen(3000, '127.0.0.1', () => { console.log('服务器运行在 http://127.0.0.1:3000/'); }); 使用 Server 类创建 # const http = require('http'); const server = new http.Server((req, res) => { // 设置统一响应头 res.writeHead(200, { 'Content-Type': 'text/plain' }); // 设置统一响应体 res.end('Hello World\n'); }); server.listen(3001); 处理不同请求方法 # const http = require('http'); // 2. 使用 Server 类 const server = new http.Server((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello World\n'); }); server.listen(3001); // 处理不同请求方法 const server = http.createServer((req, res) => { switch (req.method) { case 'GET': handleGet(req, res); break; case 'POST': handlePost(req, res); break; default: res.writeHead(405); res.end('Method Not Allowed'); } }); // get 方法处理函数 function handleGet(req, res) { res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ message: 'GET request handled' })); } // post 方法处理函数 function handlePost(req, res) { let body = ''; req.on('data', chunk => { body += chunk.toString(); }); req.on('end', () => { try { const data = JSON.parse(body); res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ received: data })); } catch (e) { res.writeHead(400); res.end('Invalid JSON'); } }); } 服务端事件 # // 1. 连接事件 server.on('connection', (socket) => { console.log('新连接建立'); socket.on('data', (chunk) => { console.log('收到数据:', chunk.toString()); }); socket.on('end', () => { console.log('连接结束'); }); socket.on('error', (err) => { console.error('Socket 错误:', err); }); }); // 2. 请求事件 server.on('request', (req, res) => { console.log('收到请求:', req.method, req.url); }); // 3. 错误事件 server.on('error', (err) => { console.error('服务器错误:', err); }); // 4. 关闭事件 server.on('close', () => { console.log('服务器关闭'); }); // 5. 监听事件 server.on('listening', () => { console.log('服务器开始监听'); }); 服务端常用方法 # // 1. 启动服务器 server.listen(3000, '127.0.0.1', () => { console.log('服务器运行在 http://127.0.0.1:3000/'); }); // 2. 关闭服务器 server.close(() => { console.log('服务器已关闭'); }); // 3. 获取服务器地址信息 const address = server.address(); console.log('服务器地址:', address); // { address: '127.0.0.1', family: 'IPv4', port: 3000 } // 4. 设置超时 server.setTimeout(60000); // 60 秒 server.on('timeout', (socket) => { console.log('连接超时'); }); // 5. 获取最大头信息大小 const maxHeaderSize = server.maxHeaderSize; console.log('最大头信息大小:', maxHeaderSize); // 6. 设置最大头信息大小 server.maxHeaderSize = 16384; // 16KB 回调函数 # 请求对象 (http.IncomingMessage) # 即我们在创建 server 时回调函数的第一个参数