Blogger Information
Blog 87
fans 1
comment 0
visits 58867
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
异步请求、 npm 与 node模块的学习
阿杰
Original
533 people have browsed it

一、异步请求的学习

(1)fetch函数

  1. fetch('http://xhr.test.com/users.php')
  2. .then(response => response.json())
  3. .then(json => console.log(json))

(2)async与await 简化fetch

  1. // async 与 await 简化fetch
  2. async function getUser(){
  3. let url = 'http://xhr.test.com/users.php';
  4. const response = await fetch(url);
  5. const result = await response.json();
  6. console.log(result);
  7. }

二、npm 常用操作

(1)初始化项目

  1. npm init -y

(2)npm安装axios包

  1. npm i axios

(3)npm删除axios包

  1. npm uni axios

三、node模块

(1)模块的声明

  1. let email = '123456@php.cn';
  2. function hello(email) {
  3. return 'My email is : ' + email;
  4. }
  5. let user = { x: 1, y: 2 };
  6. class Demo {
  7. show() {
  8. return 'Hello php.cn';
  9. }
  10. }

(2)模块的导出

  1. export { email, hello, user, Demo };

(3)模块的导入

  1. <script type="module">
  2. // 导入模板
  3. import * as myData from './module.js';
  4. // 当前空间前缀: myData
  5. console.log(myData);
  6. console.log(myData.email);
  7. console.log(myData.hello(myData.email));
  8. console.log(myData.user);
  9. console.log((new myData.Demo()).show());
  10. </script>

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