Merge branch 'base' into tabbar

This commit is contained in:
菲鸽 2024-05-25 19:28:18 +08:00
commit 7ab753ee8d
3 changed files with 26 additions and 11 deletions

View File

@ -1,3 +1,5 @@
import { UnwrapRef } from 'vue'
type IUseRequestOptions<T> = { type IUseRequestOptions<T> = {
/** 是否立即执行如果是则在onLoad执行 */ /** 是否立即执行如果是则在onLoad执行 */
immediate?: boolean immediate?: boolean
@ -19,12 +21,12 @@ export default function useRequest<T>(
) { ) {
const loading = ref(false) const loading = ref(false)
const error = ref(false) const error = ref(false)
const data = ref<T>() const data = ref<T>(options.initialData)
const run = async () => { const run = async () => {
loading.value = true loading.value = true
func() func()
.then((res) => { .then((res) => {
data.value = res.data data.value = res.data as UnwrapRef<T>
error.value = false error.value = false
}) })
.catch((err) => { .catch((err) => {

View File

@ -24,9 +24,14 @@
<!-- http://localhost:9000/#/pages/index/request --> <!-- http://localhost:9000/#/pages/index/request -->
<wd-button @click="run" class="my-6">发送请求</wd-button> <wd-button @click="run" class="my-6">发送请求</wd-button>
<view class="text-xl">请求数据如下</view> <view class="h-12">
<view class="text-green h-6">{{ JSON.stringify(data) }}</view> <view v-if="loading">loading...</view>
<wd-button type="error" @click="reset" class="my-6">清除数据</wd-button> <block v-else>
<view class="text-xl">请求数据如下</view>
<view class="text-green leading-8">{{ JSON.stringify(data) }}</view>
</block>
</view>
<wd-button type="error" @click="reset" class="my-6" :disabled="!data">重置数据</wd-button>
</view> </view>
</template> </template>
@ -35,9 +40,16 @@ import { getFooAPI, postFooAPI, IFooItem } from '@/service/index/foo'
const recommendUrl = ref('http://laf.run/signup?code=ohaOgIX') const recommendUrl = ref('http://laf.run/signup?code=ohaOgIX')
// const initialData = {
// name: 'initialData',
// id: '1234',
// }
const initialData = undefined
// Service // Service
const { loading, error, data, run } = useRequest<IFooItem>(() => getFooAPI('菲鸽')) const { loading, error, data, run } = useRequest<IFooItem>(() => getFooAPI('菲鸽'), {
initialData,
})
const reset = () => { const reset = () => {
data.value = undefined data.value = initialData
} }
</script> </script>

View File

@ -12,7 +12,7 @@ import {
import { presetApplet, presetRemRpx, transformerAttributify } from 'unocss-applet' import { presetApplet, presetRemRpx, transformerAttributify } from 'unocss-applet'
// @see https://unocss.dev/presets/legacy-compat // @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 const isMp = process.env?.UNI_PLATFORM?.startsWith('mp') ?? false
@ -43,9 +43,10 @@ export default defineConfig({
// 将颜色函数 (rgb()和hsl()) 从空格分隔转换为逗号分隔更好的兼容性app端example // 将颜色函数 (rgb()和hsl()) 从空格分隔转换为逗号分隔更好的兼容性app端example
// `rgb(255 0 0)` -> `rgb(255, 0, 0)` // `rgb(255 0 0)` -> `rgb(255, 0, 0)`
// `rgba(255 0 0 / 0.5)` -> `rgba(255, 0, 0, 0.5)` // `rgba(255 0 0 / 0.5)` -> `rgba(255, 0, 0, 0.5)`
presetLegacyCompat({ // 与群友的正常写法冲突先去掉2024-05-25
commaStyleColorFunction: true, // presetLegacyCompat({
}) as Preset, // commaStyleColorFunction: true,
// }) as Preset,
], ],
/** /**
* *