從 ItemSearch.vue 呼叫 lookUpItem 函式時,我得到未定義。
物品搜索.vue
<script setup lang="ts">
import { lookUpItem } from '../systemApi'
async function getItemDetails() {
const response = await lookUpItem(mNumber, location)
}
</script>
系統API.ts
export async function lookUpItem(mNumber: number, location: number) {
getHash().then((hash) => {
axios.get(url)
.then((response) => {
// console.log(response) <- outputs the correct data to console.
return response
}
uj5u.com熱心網友回復:
你可以試試這個:
為了更好地閱讀(和理解)
export async function lookUpItem(mNumber: number, location: number) {
try{
const hash = await getHash();
const response = await axios.get(url);
return response;
}catch(err){
throw err;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/468685.html
標籤:javascript 打字稿 Vuejs3
上一篇:從物件型別構造聯合型別
