<script lang="uts" setup>
import type { BaseRoot, Lives } from '../../types/http.uts'
import { gaodeKey, cityCode, baseUrl, timeout } from '../../config/base.config.uts';
import { showMessage } from '../../utils/messageApi.uts';
import { encodeRestParams } from '../../utils/common.uts';
import { myRequest } from '@/api/request.uts';
const title = ref<string>('Hello');
const todayData = ref({
province: '',
city: '',
adcode: '',
weather: '',
temperature: '',
winddirection: '',
windpower: '',
humidity: '',
reporttime: '',
temperature_float: '',
humidity_float: '',
} as Lives)
onLoad(async function (options) : Promise<void> {
try {
const res = await myRequest<BaseRoot>('base')
console.log(res)
} catch (e) {
console.log(e)
}
})
上面是部分代码,myRequest是封装的promise函数,现在想await请求,但是setup语法糖下onLoad不能用async,报错是这样子:[APP-ANDROID] 函数签名 '(options: OnLoadOptions) => Promise<void>' 无法兼容函数签名 'OnLoad'。
返回值类型 'Promise<void>' 无法赋值给返回值类型 'void'。
求教如何修正,,到底为啥。。
0 个回复