Blogger Information
Blog 43
fans 0
comment 3
visits 26842
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1. 实例演示fetch api, async,await的使用 2. npm 安装与删除包的常用操作 3. node中的模块声明,导出与导入
Time
Original
412 people have browsed it

fetch api, async,await的使用

fetch

  1. //成功then 失败catch()
  2. fetch(url).then(response=>response.json())
  3. .then(json=>console.log(json))
  4. .catch(error)

async,await简化fetch

  1. //async异步类型函数
  2. async function getUser(){
  3. const response =await fetch(url);
  4. const result = await response.json();
  5. console.log(result);
  6. }

npm 安装与删除包的常用操作

  1. //默认安装的是开发依赖:node install 包名
  2. //生产依赖:node install 包名 -D
  3. //安装(可以简写node i 包名)
  4. node install 包名
  5. //安装全局
  6. node install 包名 -g
  7. //删除(可以简写node uni 包名)
  8. node uninstall 包名
  1. *:允许大版本更新
  2. ^:允许小版本更新
  3. ~: 仅允许修复补丁

node中的模块声明,导出与导入

  1. 1.核心模块: node自带模块
  2. 2.文件模块:自定义模块
  3. 3.第三方模块:npm安装

代码示例

  1. //引入核心模块http
  2. let http = require('http');console.log(http);
  3. //文件模块|导出文件用exports 实现逐个和统一导出
  4. let site = require(导出文件路径)
  5. console.log(site.导出文件的变量或者函数名);
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post