From 65b8be6f5719daf390e0a9b656746ee114cfd4de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8F=B2=E9=B8=BD?= <1020103647@qq.com> Date: Mon, 20 May 2024 08:52:02 +0800 Subject: [PATCH 1/2] feat: initialData --- src/hooks/useRequest.ts | 6 ++++-- src/pages/about/components/request.vue | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/hooks/useRequest.ts b/src/hooks/useRequest.ts index 9cc392b..0559276 100644 --- a/src/hooks/useRequest.ts +++ b/src/hooks/useRequest.ts @@ -1,3 +1,5 @@ +import { UnwrapRef } from 'vue' + type IUseRequestOptions = { /** 是否立即执行,如果是则在onLoad执行 */ immediate?: boolean @@ -19,12 +21,12 @@ export default function useRequest( ) { const loading = ref(false) const error = ref(false) - const data = ref() + const data = ref(options.initialData) const run = async () => { loading.value = true func() .then((res) => { - data.value = res.data + data.value = res.data as UnwrapRef error.value = false }) .catch((err) => { diff --git a/src/pages/about/components/request.vue b/src/pages/about/components/request.vue index 1ca55bd..a8bf509 100644 --- a/src/pages/about/components/request.vue +++ b/src/pages/about/components/request.vue @@ -24,9 +24,14 @@ 发送请求 - 请求数据如下 - {{ JSON.stringify(data) }} - 清除数据 + + loading... + + 请求数据如下 + {{ JSON.stringify(data) }} + + + 重置数据 @@ -35,9 +40,16 @@ import { getFooAPI, postFooAPI, IFooItem } from '@/service/index/foo' const recommendUrl = ref('http://laf.run/signup?code=ohaOgIX') +// const initialData = { +// name: 'initialData', +// id: '1234', +// } +const initialData = undefined // 适合少部分全局性的接口————多个页面都需要的请求接口,额外编写一个 Service 层 -const { loading, error, data, run } = useRequest(() => getFooAPI('菲鸽')) +const { loading, error, data, run } = useRequest(() => getFooAPI('菲鸽'), { + initialData, +}) const reset = () => { - data.value = undefined + data.value = initialData } From ab7c5f97e4ab4a06adaf59da29656b5341e67e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8F=B2=E9=B8=BD?= <1020103647@qq.com> Date: Sat, 25 May 2024 19:27:55 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat(unocss):=20=E5=85=88=E5=8E=BB=E6=8E=89?= =?UTF-8?q?=20presetLegacyCompat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uno.config.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/uno.config.ts b/uno.config.ts index 435d7d8..f97cfcf 100644 --- a/uno.config.ts +++ b/uno.config.ts @@ -12,7 +12,7 @@ import { import { presetApplet, presetRemRpx, transformerAttributify } from 'unocss-applet' // @see https://unocss.dev/presets/legacy-compat -import { presetLegacyCompat } from '@unocss/preset-legacy-compat' +// import { presetLegacyCompat } from '@unocss/preset-legacy-compat' const isMp = process.env?.UNI_PLATFORM?.startsWith('mp') ?? false @@ -43,9 +43,10 @@ export default defineConfig({ // 将颜色函数 (rgb()和hsl()) 从空格分隔转换为逗号分隔,更好的兼容性app端,example: // `rgb(255 0 0)` -> `rgb(255, 0, 0)` // `rgba(255 0 0 / 0.5)` -> `rgba(255, 0, 0, 0.5)` - presetLegacyCompat({ - commaStyleColorFunction: true, - }) as Preset, + // 与群友的正常写法冲突,先去掉!(2024-05-25) + // presetLegacyCompat({ + // commaStyleColorFunction: true, + // }) as Preset, ], /** * 自定义快捷语句