request.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <route lang="json5">
  2. {
  3. layout: 'demo',
  4. style: {
  5. navigationBarTitleText: '请求',
  6. },
  7. }
  8. </route>
  9. <template>
  10. <view class="p-6 text-center">
  11. <view class="my-2">使用的是 laf 云后台</view>
  12. <view class="text-green-400">我的推荐码,可以获得佣金</view>
  13. <!-- #ifdef H5 -->
  14. <view class="my-2">
  15. <a class="my-2" :href="recommendUrl" target="_blank">{{ recommendUrl }}</a>
  16. </view>
  17. <!-- #endif -->
  18. <!-- #ifndef H5 -->
  19. <view class="my-2 text-left text-sm">{{ recommendUrl }}</view>
  20. <!-- #endif -->
  21. <!-- http://localhost:9000/#/pages/index/request -->
  22. <button @click="getFoo" class="my-6">1.测试 GET 请求</button>
  23. <view class="text-xl">请求数据如下</view>
  24. <view class="text-green h-10">{{ JSON.stringify(data) }}</view>
  25. <view class="text-xl">完整数据</view>
  26. <view class="text-green h-16">{{ JSON.stringify(originalData) }}</view>
  27. <button @click="postFoo" class="my-6">2.测试 POST 请求</button>
  28. <view class="text-xl">请求数据如下</view>
  29. <view class="text-green h-10">{{ JSON.stringify(data2) }}</view>
  30. <button class="my-6" type="warn" @click="reset">3.一键清空数据</button>
  31. </view>
  32. </template>
  33. <script lang="ts" setup>
  34. import { getFooAPI, postFooAPI, IFooItem } from '@/service/index/foo'
  35. const recommendUrl = ref('http://laf.run/signup?code=ohaOgIX')
  36. onLoad(() => {
  37. getFoo()
  38. postFoo()
  39. })
  40. const originalData = ref<IResData<IFooItem>>()
  41. const data = ref<IFooItem>()
  42. const getFoo = async () => {
  43. const res = await getFooAPI('菲鸽')
  44. data.value = res.data
  45. originalData.value = res
  46. }
  47. const data2 = ref<IFooItem>()
  48. const postFoo = async () => {
  49. const res = await postFooAPI('菲鸽2')
  50. data2.value = res.data
  51. }
  52. const reset = () => {
  53. data.value = undefined
  54. data2.value = undefined
  55. originalData.value = undefined
  56. }
  57. </script>