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

1
2

  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;
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!