ASCII码 ASCII码

npm 安装与删除包的常用操作及 node中的模块声明,导出与导入

发布于:2022-04-24 11:07:19  栏目:技术文档

  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. <script src="https://unpkg.com/vue@next"></script>
  9. <style>
  10. button{
  11. background-color: red;
  12. font-size: 32px;
  13. color: rgb(245, 241, 241);
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <button onclick="getData()">fecth</button>
  19. <button onclick="getDataOne()">await</button>
  20. <script>
  21. //1. 实例演示fetch api, async,await的使用
  22. function getData() {
  23. fetch("http://xhr411.edu/users.php")
  24. .then((response) => response.json())
  25. .then((json) => console.log(json));
  26. }
  27. const url = "http://xhr411.edu/users.php";
  28. async function getDataOne(){
  29. const response = await fetch(url);
  30. const result = await response.json();
  31. console.log(result);
  32. }
  33. </script>
  34. </body>
  35. </html>

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

  1. // 1. 核心模块
  2. const http = require('http');
  3. console.log(http);
  4. // 2. 文件模块
  5. const demo = require('./demo.js');
  6. console.log(demo.getuser())
  7. let user = "php.cn";
  8. function getuser(){
  9. return this.user;
  10. }
  11. exports.user = user;
  12. exports.getuser = getuser;
相关推荐
阅读 +