Skip to content

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
swlws committed Jul 6, 2024
1 parent e639771 commit a7bfce2
Show file tree
Hide file tree
Showing 3 changed files with 400 additions and 13 deletions.
26 changes: 13 additions & 13 deletions config/date/202406/http-interceptor.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ head:
- window.navigator.sendBeacon
- new Image

针对这几种不同的场景,分别拦截处理它的URL和请求参数
针对这几种不同的场景,分别拦截处理它的 URL 和请求参数

## (一)设计

Expand Down Expand Up @@ -51,7 +51,7 @@ XHR 的核心思路:
```ts
class CustomXhr extends NativeXhr {
private _method!: string;
private _src = '' as K;
private _src = "" as K;
private _async!: boolean;
private _username?: string | null;
private _password?: string | null;
Expand All @@ -76,21 +76,15 @@ class CustomXhr extends NativeXhr {
}

send(body?: T) {
let url = '' as K;
let url = "" as K;
let data = body;

if (!_this.useNative) {
[url, data] = _this.callFilterAndAdapter(this._src, body);
}

// Open
super.open(
this._method,
url,
this._async,
this._username,
this._password
);
super.open(this._method, url, this._async, this._username, this._password);

// 设置请请求头
Object.keys(this._headers).forEach((key) => {
Expand Down Expand Up @@ -161,7 +155,7 @@ window.navigator.sendBeacon = (url: K, data: T) => {
核心代码实现:

```ts
const NativeImage = window.Image;
const NativeImage = window.Image;

class CustomImage extends NativeImage {
private _src!: K;
Expand All @@ -173,7 +167,7 @@ class CustomImage extends NativeImage {
}

this._src = _this.newSetHandler(value);
this.setAttribute('src', this._src);
this.setAttribute("src", this._src);
}

get src() {
Expand All @@ -186,4 +180,10 @@ window.Image = CustomImage;

## (三)源码

[源代码: https://github.com/swlws/http-interceptor](https://github.com/swlws/http-interceptor)
### install

```bash
npm i @swl/http-interceptor
```

[源代码: https://github.com/swlws/http-interceptor](https://github.com/swlws/http-interceptor)
25 changes: 25 additions & 0 deletions config/interview/虾皮-一面-苏格拉底看烟花.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 虾皮(一面)- 苏格拉底看烟花

## 对 React 和 Vue 框架的理解

## 前端性能优化的方法

## 构建工具 webpack、rollup

## 什么是单页应用

## 有哪些前端自动化测试的经验

## GIT 的使用经验

## eslint 的使用

## 前端调试工具,比如:Chrome 开发者工具

## 对前端状态管理的理解

## 前端跨域问题的处理方法

## JS 异步的原理

JavaScript 是单线程的,这意味着在同一时间只能执行一个任务。为了实现异步操作,JavaScript 使用了事件循环(Event Loop)、任务队列(Task Queue)、回调函数(Callbacks)、Promises 和 async/await 等机制
Loading

0 comments on commit a7bfce2

Please sign in to comment.