Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
JOU-amjs committed Nov 4, 2024
2 parents a1f29c9 + f86e5c6 commit 79d8ecb
Show file tree
Hide file tree
Showing 29 changed files with 218 additions and 92 deletions.
11 changes: 9 additions & 2 deletions docs/resource/01-request-adapter/01-alova-mock.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@ This mock plug-in is an alova request adapter. Different from the traditional Pr
<TabItem value="1" label="npm">

```bash
npm install @alova/mock --save
npm install alova @alova/mock --save
```

</TabItem>
<TabItem value="2" label="yarn">

```bash
yarn add @alova/mock
yarn add alova @alova/mock
```

</TabItem>
<TabItem value="3" label="pnpm">

```bash
pnpm install alova @alova/mock
```

</TabItem>
Expand Down
11 changes: 9 additions & 2 deletions docs/resource/01-request-adapter/03-xhr.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ import TabItem from '@theme/TabItem';
<TabItem value="1" label="npm">

```bash
npm install @alova/adapter-xhr --save
npm install alova @alova/adapter-xhr --save
```

</TabItem>
<TabItem value="2" label="yarn">

```bash
yarn add @alova/adapter-xhr
yarn add alova @alova/adapter-xhr
```

</TabItem>
<TabItem value="3" label="pnpm">

```bash
pnpm install alova @alova/adapter-xhr
```

</TabItem>
Expand Down
11 changes: 9 additions & 2 deletions docs/resource/01-request-adapter/04-axios.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ import TabItem from '@theme/TabItem';
<TabItem value="1" label="npm">

```bash
npm install @alova/adapter-axios axios --save
npm install alova @alova/adapter-axios axios --save
```

</TabItem>
<TabItem value="2" label="yarn">

```bash
yarn add @alova/adapter-axios axios
yarn add alova @alova/adapter-axios axios
```

</TabItem>
<TabItem value="3" label="pnpm">

```bash
pnpm install alova @alova/adapter-axios axios
```

</TabItem>
Expand Down
25 changes: 7 additions & 18 deletions docs/resource/01-request-adapter/05-uniapp.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,25 @@ This plugin only supports vue3 version of uniapp application.
<TabItem value="1" label="npm">

```bash
npm install @alova/adapter-uniapp --save
npm install alova @alova/adapter-uniapp @alova/shared --save
```

</TabItem>
<TabItem value="2" label="yarn">

```bash
yarn add @alova/adapter-uniapp
yarn add alova @alova/adapter-uniapp @alova/shared
```

</TabItem>
</Tabs>

:::warning

In uniapp+vite, `@rollup/plugin-node-resolve` needs to be configured, otherwise it may cause an error that the dependency cannot be found.

[#535 discussion](https://github.com/orgs/alovajs/discussions/535)

```js
import { defineConfig } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
import { nodeResolve } from '@rollup/plugin-node-resolve';
<TabItem value="3" label="pnpm">

export default defineConfig({
plugins: [uni(), nodeResolve()]
});
```bash
pnpm install alova @alova/adapter-uniapp @alova/shared
```

:::
</TabItem>
</Tabs>

## Usage

Expand Down
25 changes: 16 additions & 9 deletions docs/resource/01-request-adapter/06-taro.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@ This plugin only supports the taro application of react 16.8+, vue3 version.
<TabItem value="1" label="npm">

```bash
npm install @alova/adapter-taro --save
npm install alova @alova/adapter-taro --save
```

</TabItem>
<TabItem value="2" label="yarn">

```bash
yarn add @alova/adapter-taro
yarn add alova @alova/adapter-taro
```

</TabItem>
<TabItem value="3" label="pnpm">

```bash
pnpm install alova @alova/adapter-taro
```

</TabItem>
Expand All @@ -40,7 +47,7 @@ If you are develop a React-Native app with Taro, please ensure `metro >= 0.76.0`

:::warning Dependency precompilation issues

[Dependency precompilation function](https://docs.taro.zone/blog/2022/05/19/Taro-3.5-beta#2-%E4%BE%9D%E8%B5%96%E9%A2%84%E7%BC%96%E8%AF%91) has been added in Taro v3.5 beta, and is enabled by default in development mode when you are using the `alova` library and `@alova/scene-react(vue)` may cause the error `` [alova]can not call useHooks until set the `statesHook` at alova instance. ``. This is caused by the prebundle feature repeatedly packaging two different `alova` packages. , turning off the prebundle function at this time can solve this problem.
[Dependency precompilation function](https://docs.taro.zone/blog/2022/05/19/Taro-3.5-beta#2-%E4%BE%9D%E8%B5%96%E9%A2%84%E7%BC%96%E8%AF%91) has been added in Taro v3.5 beta, and is enabled by default in development mode when you are using the `alova` library and `@alova/scene-react(vue)` may cause the error ``[alova]can not call useHooks until set the `statesHook` at alova instance.``. This is caused by the prebundle feature repeatedly packaging two different `alova` packages. , turning off the prebundle function at this time can solve this problem.

```js
// config/dev.ts
Expand Down Expand Up @@ -162,11 +169,11 @@ const uploadFile = (name, filePath, formData) =>
name,
filePath,

// Additional data will be passed into formData of uni.uploadFile
// Additional data will be passed into formData of Taro.uploadFile
...formData
},
{
// Set the request method to upload, and the adapter will call uni.uploadFile
// Set the request method to upload, and the adapter will call Taro.uploadFile
requestType: 'upload'
}
);
Expand Down Expand Up @@ -216,11 +223,11 @@ const App = () => {
name,
filePath,
// Additional data will be passed into formData of uni.uploadFile
// Additional data will be passed into formData of Taro.uploadFile
...formData
},
{
// Set the request method to upload, and the adapter will call uni.uploadFile
// Set the request method to upload, and the adapter will call Taro.uploadFile
requestType: 'upload'
}
);
Expand Down Expand Up @@ -258,7 +265,7 @@ Similarly, it is fully compatible with `Taro.downloadFile`, you can specify [all
```jsx
const downloadFile = filePath =>
alovaInst.Get('/bigImage.jpg', {
// Set the request method to download, and the adapter will call uni.downloadFile
// Set the request method to download, and the adapter will call Taro.downloadFile
requestType: 'download',
filePath
});
Expand Down Expand Up @@ -294,7 +301,7 @@ const App = () => {
<script setup>
const downloadFile = filePath =>
alovaInst.Get('/bigImage.jpg', {
// Set the request method to download, and the adapter will call uni.downloadFile
// Set the request method to download, and the adapter will call Taro.downloadFile
requestType: 'download',
filePath
});
Expand Down
7 changes: 6 additions & 1 deletion docs/resource/02-storage-adapter/01-psc.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ Only supports Alova 3.0 and above.
## Install

```bash
npm install @alova/psc --save
# npm
npm install alova @alova/psc --save
# yarn
yarn add alova @alova/psc
# npm
pnpm install alova @alova/psc
```

## Use in Node.js
Expand Down
7 changes: 7 additions & 0 deletions docs/resource/03-framework/07-vue-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ npm install alova @alova/vue-options --save
yarn add alova @alova/vue-options
```

</TabItem>
<TabItem value="3" label="pnpm">

```bash
pnpm install alova @alova/vue-options
```

</TabItem>
</Tabs>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ flowchart LR
```javascript
const alovaInstance = createAlova({
// ...
//Use two items of the array to specify the interceptor for successful request and the interceptor for failed request respectively.
// Use responded object to specify the interceptor for successful request and the interceptor for failed request respectively.
responded: {
// highlight-start
// Interceptor for successful request
Expand Down
8 changes: 7 additions & 1 deletion docs/tutorial/03-client/01-strategy/14-use-sse.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ use hook

> Before using extended hooks, make sure you are familiar with the basic use of alova.
Request through Server-sent Events (SSE), internally implemented using `EventSource`.
This hook is implemented using the `EventSource` API.

::: warning note

When you are not to be used in useSSE add custom header, because the standard [does not contain the behavior](https://stackoverflow.com/a/36226251)

:::

## Features

Expand Down
10 changes: 6 additions & 4 deletions docs/tutorial/07-project/01-best-practice/06-middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ When the response is very fast, the loading status will flash once, which will b
const delayLoadingMiddleware =
(delayTimer = 1000) =>
async (ctx, next) => {
//Control loading by yourself
const { loading } = ctx.proxyStates;

// Control loading by yourself
ctx.controlLoading();

//Delay updates for a specific time
// Delay updates for a specific time
const timer = setTimeout(() => {
ctx.update({ loading: true });
loading.v = true;
}, delayTimer);
await next();
ctx.update({ loading: false });
loading.v = false;
clearTimeout(timer);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@ import TabItem from '@theme/TabItem';
<TabItem value="1" label="npm">

```bash
npm install @alova/mock --save
npm install alova @alova/mock --save
```

</TabItem>
<TabItem value="2" label="yarn">

```bash
yarn add @alova/mock
yarn add alova @alova/mock
```

</TabItem>
<TabItem value="3" label="pnpm">

```bash
pnpm install alova @alova/mock
```

</TabItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ import TabItem from '@theme/TabItem';
<TabItem value="1" label="npm">

```bash
npm install @alova/adapter-xhr --save
npm install alova @alova/adapter-xhr --save
```

</TabItem>
<TabItem value="2" label="yarn">

```bash
yarn add @alova/adapter-xhr
yarn add alova @alova/adapter-xhr
```

</TabItem>
<TabItem value="3" label="pnpm">

```bash
pnpm install alova @alova/adapter-xhr
```

</TabItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ import TabItem from '@theme/TabItem';
<TabItem value="1" label="npm">

```bash
npm install @alova/adapter-axios axios --save
npm install alova @alova/adapter-axios axios --save
```

</TabItem>
<TabItem value="2" label="yarn">

```bash
yarn add @alova/adapter-axios axios
yarn add alova @alova/adapter-axios axios
```

</TabItem>
<TabItem value="3" label="pnpm">

```bash
pnpm install alova @alova/adapter-axios axios
```

</TabItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,25 @@ import TabItem from '@theme/TabItem';
<TabItem value="1" label="npm">

```bash
npm install @alova/adapter-uniapp --save
npm install alova @alova/adapter-uniapp @alova/shared --save
```

</TabItem>
<TabItem value="2" label="yarn">

```bash
yarn add @alova/adapter-uniapp
yarn add alova @alova/adapter-uniapp @alova/shared
```

</TabItem>
</Tabs>

:::warning

在 uniapp+vite 中,需要配置`@rollup/plugin-node-resolve`,否则可能导致找不到依赖报错。

[#535 discussion](https://github.com/orgs/alovajs/discussions/535)

```js
import { defineConfig } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
import { nodeResolve } from '@rollup/plugin-node-resolve';
<TabItem value="3" label="pnpm">

export default defineConfig({
plugins: [uni(), nodeResolve()]
});
```bash
pnpm install alova @alova/adapter-uniapp @alova/shared
```

:::
</TabItem>
</Tabs>

## 使用方法

Expand Down
Loading

0 comments on commit 79d8ecb

Please sign in to comment.