瀏覽代碼

feat: 请求增加返回类型

Burt 2 年之前
父節點
當前提交
e29cfe99dc
共有 2 個文件被更改,包括 8 次插入3 次删除
  1. 4 3
      src/pages/index/index.vue
  2. 4 0
      src/typings.d.ts

+ 4 - 3
src/pages/index/index.vue

@@ -7,7 +7,7 @@
     <button @click="setUserInfo">设置UserInfo</button>
     <button @click="clearUserInfo">清除UserInfo</button>
 
-    <button @click="request">请求</button>
+    <button @click="handleRequest">请求</button>
     <view class="flex justify-center items-center text-blue-500">
       Demo Count: {{ countStore.count }}
       <button class="ml-2" @click="countStore.increment">新增</button>
@@ -28,6 +28,7 @@
 import { ref } from 'vue'
 import { useCountStore, useUserStore } from '@/store'
 import { http } from '@/utils/http'
+import { UserItem } from '@/typings'
 
 const countStore = useCountStore()
 const title = ref('Hello')
@@ -43,8 +44,8 @@ const setUserInfo = () => {
 const clearUserInfo = () => {
   userStore.clearUserInfo()
 }
-const request = () => {
-  const res = http({
+const handleRequest = () => {
+  const res = http<UserItem[]>({
     url: '/getUserList',
     method: 'GET',
   })

+ 4 - 0
src/typings.d.ts

@@ -2,3 +2,7 @@ export type UserInfo = {
   username: string
   token: string
 }
+export type UserItem = {
+  username: string
+  age: number
+}