(1)fetch函数
fetch('http://xhr.test.com/users.php')
.then(response => response.json())
.then(json => console.log(json))
(2)async与await 简化fetch
// async 与 await 简化fetch
async function getUser(){
let url = 'http://xhr.test.com/users.php';
const response = await fetch(url);
const result = await response.json();
console.log(result);
}
(1)初始化项目
npm init -y
(2)npm安装axios包
npm i axios
(3)npm删除axios包
npm uni axios
(1)模块的声明
let email = '123456@php.cn';
function hello(email) {
return 'My email is : ' + email;
}
let user = { x: 1, y: 2 };
class Demo {
show() {
return 'Hello php.cn';
}
}
(2)模块的导出
export { email, hello, user, Demo };
(3)模块的导入
<script type="module">
// 导入模板
import * as myData from './module.js';
// 当前空间前缀: myData
console.log(myData);
console.log(myData.email);
console.log(myData.hello(myData.email));
console.log(myData.user);
console.log((new myData.Demo()).show());
</script>
相关推荐
© 2020 asciim码
人生就是一场修行