57 lines
1.6 KiB
Vue
Raw Normal View History

2024-05-15 10:06:51 +08:00
<route lang="json5">
{
layout: 'demo',
style: {
navigationBarTitleText: '请求',
},
}
</route>
<template>
<view class="p-6 text-center">
<view class="my-2">使用的是 laf 云后台</view>
<view class="text-green-400">我的推荐码可以获得佣金</view>
<!-- #ifdef H5 -->
<view class="my-2">
<a class="my-2" :href="recommendUrl" target="_blank">{{ recommendUrl }}</a>
</view>
<!-- #endif -->
<!-- #ifndef H5 -->
<view class="my-2 text-left text-sm">{{ recommendUrl }}</view>
<!-- #endif -->
<!-- http://localhost:9000/#/pages/index/request -->
2024-05-18 17:57:35 +08:00
<wd-button @click="run" class="my-6">发送请求</wd-button>
2024-05-20 08:52:02 +08:00
<view class="h-12">
<view v-if="loading">loading...</view>
<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>
2024-05-15 10:06:51 +08:00
</view>
</template>
<script lang="ts" setup>
import { getFooAPI, postFooAPI, IFooItem } from '@/service/index/foo'
const recommendUrl = ref('http://laf.run/signup?code=ohaOgIX')
2024-05-20 08:52:02 +08:00
// const initialData = {
// name: 'initialData',
// id: '1234',
// }
const initialData = undefined
2024-05-15 10:06:51 +08:00
// 适合少部分全局性的接口————多个页面都需要的请求接口,额外编写一个 Service 层
2024-05-20 08:52:02 +08:00
const { loading, error, data, run } = useRequest<IFooItem>(() => getFooAPI('菲鸽'), {
immediate: true,
2024-05-20 08:52:02 +08:00
initialData,
})
2024-05-15 10:06:51 +08:00
const reset = () => {
2024-05-20 08:52:02 +08:00
data.value = initialData
2024-05-15 10:06:51 +08:00
}
</script>