ASCII码 ASCII码

实例演示fetch api, async,await的使用 & npm 安装与删除包的常用操作 & node中的模块声明,导出与导入

发布于:2022-04-19 14:00:48  栏目:技术文档

12

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <button onclick="getData()">fecth</button>
  11. <button onclick="getDataOne()">await</button>
  12. </body>
  13. <script>
  14. //1. 实例演示fetch api, async,await的使用
  15. function getData() {
  16. fetch("http://xhr411.edu/users.php")
  17. .then((response) => response.json())
  18. .then((json) => console.log(json));
  19. }
  20. const url = "http://xhr411.edu/users.php";
  21. async function getDataOne(){
  22. const response = await fetch(url);
  23. const result = await response.json();
  24. console.log(result);
  25. }
  26. </script>
  27. </html>

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

  1. npm i/install xxx 生产环境包xxx
  2. npm i/install -D xxx 开发环境包xxx
  3. npm i/install -g xxx 全局生产环境包xxx
  4. npm uni/unistall xxx 卸载包xxx
  1. //3. node中的模块声明,导出与导入
  2. // 1. 核心模块
  3. const http = require('http');
  4. console.log(http);
  5. // 2. 文件模块
  6. const demo = require('./demo.js');
  7. console.log(demo.getuser());
  1. let user = "php.cn";
  2. function getuser(){
  3. return this.user;
  4. }
  5. exports.user = user;
  6. exports.getuser = getuser;
相关推荐
阅读 +