From 877e9e720894e0d0916fd02bf9354fcb2ad6516e Mon Sep 17 00:00:00 2001
From: Tsanie Lily
Content-Type 请求头的值
+ 自定义请求头,例如
+ customerHeaders?: { [key: string]: string }
+ {
+ 'X-Auth-Id': 'xxxxxx',
+ 'X-Auth-Token': 'xxxxxx'
+}
+
+ 终止器的信号,用来控制终止请求任务 +
++ 调用 upload 方法时在上传过程中触发的事件,返回进度参数 +
++ 返回一个结果为 Response 对象的 Promise +
+function post(url: string, data?: BodyInit | null, options?: RequestOptions): Promise<Response>
+ + url 地址 +
++ post 请求传递的请求正文,可以是 FormData 或者任意对象,后者会经 JSON 序列化后发送 +
++ 请求的配置参数,结构如上述 get +
++ 返回一个结果为 Response 对象的 Promise +
+upload(url: string, data: FormData, options?: RequestOptions): Promise<XMLHttpRequest>
+ + url 地址 +
++ upload 请求传递的请求正文,仅支持 FormData +
+
+ 请求的配置参数,结构如上述 get,仅使用其中 progress 与 customerHeaders
+
+ 返回一个结果为 XMLHttpRequest 对象的 Promise +
+const request = window["lib-utility"];
+
+request.get('https://www.baidu.com')
+ .then(r => r.text())
+ .then(text => console.log(text));
+
+request.post('api/query', { id: 101 })
+ .then(r => r.json())
+ .then(result => console.log(result.data));
+
+request.upload('api/upload', data, {
+ progress: (ev) => {
+ console.log(`loaded: ${ev.loaded}, total: ${ev.total}`);
+ }
+})
+ .then(() => console.log('done.'));
\ No newline at end of file
diff --git a/main.js b/main.js
index ed45e60..7ec72c6 100644
--- a/main.js
+++ b/main.js
@@ -19,7 +19,9 @@ function navigate(page) {
const range = document.createRange();
range.selectNode(document.body);
const doc = range.createContextualFragment(html);
- document.querySelector('#container').replaceChildren(doc);
+ const container = document.querySelector('#container');
+ container.replaceChildren(doc);
+ container.scrollTop = 0;
});
}