😗Node.js
2019-2-20
| 2022-9-1
0  |  0 分钟
type
status
date
slug
summary
tags
category
icon
password
URL
Sep 1, 2022 09:23 AM

懒加载

懒加载就是延迟加载,是一种对网页性能优化的方式,比如当访问一个页面的时候,优先显示可视区域的图片而不一次性加载所有的图片,当需要显示的时候再发送图片请求,避免打开网页时加载过多的资源
 
需要用到的知识点
img.offsetTop
window.innerHeight
document.body.scrollTop || document.documentElement.scrollTop
 

Node.js是什么

Nodejs是一个平台,提供了JS运行环境,并且添加了大量的API
Node.js平台=js引擎+大量API
 
Node的安装
通过node -v命令查看是否安装完成
node filename
在文件夹浏览器中输入cmd命令
 
Node搭建服务器
const http = require("http")
类似于new http()
可以理解为创建一个http类型的对象
 
http.createServer(function(req,res){
res.writeHead(200,{"Content-type":"text/html;charset"});
res.write("hahaha");
res.end("is over");}).listen(8888)
 
nodejs 中的模块化
模块就是类,node用模块的概念淡化了类的概念
模块的分类
1.内置模块 http,fs
2.自定义模块,就是用户自己写的js文件
3.第三方模块,通过网络商城下载(NPM)
问题:js文件时如何相互引入
commonJS:提供模块导入和导出的标准语法
 
导入
require(fileName)
 
导出:又叫暴露
module.exports
module.exports = {}
exports不能以对象的形式暴露
exports.自定义属性
 
路径问题
node_modules文件夹内的所有js是可以不加路径的
如果node_modules里面有文件夹,则require文件夹名,等价于导入该文件夹下的index.js模块
 
 
ES6模块化
import{a1,a2,a3...} form "path"
export or function
最后还要在html上引入添加type = "module"
 
notion image
 
npm install or npm i
npm uninstall
nodemon (restart)
npm install -g nodemon
 
学习思考
  • javascript
  • 函数函数对象和闭包
    • Valine
    • Cusdis
    目录