-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: update deps * chore: update siteTitle, add local search * docs: update
- Loading branch information
Showing
12 changed files
with
1,408 additions
and
708 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import antfu from '@antfu/eslint-config' | ||
|
||
export default antfu() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,29 @@ | ||
# 数据获取 | ||
|
||
你可以使用任何你喜欢的第三方请求库来获取数据。默认情况下,直接使用 `uni.request` 即可。 | ||
你可以使用你喜欢的第三方请求库来获取数据。一般情况下,直接使用 `uni-app` 内置方法即可。 | ||
|
||
## `uni.request` | ||
## `uni-app` 内置方法 | ||
|
||
这是 uni 内置的网络请求方法。 | ||
`uni-app` 提供了 [uni.request](https://uniapp.dcloud.net.cn/api/request/request.html)、[uni.uploadFile](https://uniapp.dcloud.net.cn/api/request/network-file.html#uploadfile)、[uni.downloadFile](https://uniapp.dcloud.net.cn/api/request/network-file.html#downloadfile)、[WebSocket](https://uniapp.dcloud.net.cn/api/request/websocket.html) 等支持。一般情况下,你可以直接使用它们。 | ||
|
||
```ts | ||
uni.request({ | ||
url: 'https://www.example.com/request', | ||
data: { | ||
text: 'uni.request' | ||
}, | ||
header: { | ||
'custom-header': 'hello' // 自定义请求头信息 | ||
}, | ||
success: (res) => { | ||
console.log(res.data) | ||
} | ||
}) | ||
``` | ||
## axios | ||
|
||
如果你更喜欢 [axios](https://github.com/axios/axios) 及其相关生态,你可以使用 [@uni-helper/axios-adapter](https://github.com/uni-helper/axios-adapter)。它是专为 `uni-app` 打造的 `axios` 适配器,支持全平台! | ||
|
||
```ts | ||
import axios from 'axios' | ||
import { createUniAppAxiosAdapter } from '@uni-helper/axios-adapter' | ||
|
||
::: tip | ||
你可以在[这里](https://uniapp.dcloud.net.cn/api/request/request.html#)阅读文档。 | ||
::: | ||
axios.defaults.adapter = createUniAppAxiosAdapter() | ||
const { data, isFinished } = useAxios('/user?ID=12345') | ||
``` | ||
|
||
## uni-network | ||
## @uni-helper/uni-network | ||
|
||
这是一个为 `uni-app` 打造的 [基于 Promise](https://javascript.info/promise-basics) 的 HTTP 客户端,灵感和代码绝大部分源于 `[email protected]`。 | ||
[@uni-helper/uni-network](https://github.com/uni-helper/uni-network) 是一个为 `uni-app` 打造的基于 `Promise` 的 HTTP 客户端,灵感和代码绝大部分源于 `[email protected]`。`@uni-helper/uni-network` 在底层做了 `uni-app` 适配,体积更小,TypeScript 类型更贴近 `uni-app`。 | ||
|
||
```ts | ||
import un from '@uni-helper/uni-network' | ||
import { un } from '@uni-helper/uni-network' | ||
|
||
try { | ||
const response = await un.get('/user?ID=12345') | ||
|
@@ -41,23 +33,3 @@ catch (error) { | |
console.error(error) | ||
} | ||
``` | ||
|
||
::: tip | ||
你可以在[这里](https://github.com/uni-helper/uni-network)阅读文档。 | ||
::: | ||
|
||
## axios | ||
|
||
如果你更喜欢 axios 或者为了享受其相关生态,你还可以使用由 Uni Helper 团队开发的 [axios-adapter](https://github.com/uni-helper/axios-adapter),它是专为 uni-app 打造的 axios 适配器,支持全平台! | ||
|
||
```ts | ||
import axios from 'axios' | ||
import { createUniAppAxiosAdapter } from '@uni-helper/axios-adapter' | ||
|
||
axios.defaults.adapter = createUniAppAxiosAdapter() | ||
const { data, isFinished } = useAxios('/user?ID=12345') | ||
``` | ||
|
||
::: tip | ||
你可以阅读 [axios 的文档](https://axios-http.com/docs/intro) 和 [axios-adapter 的文档](https://github.com/uni-helper/axios-adapter)了解更多信息。 | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.