从 axios 函数获取响应
Getting response from axios function
当从 ItemSearch.vue 调用 lookUpItem 函数时,我得到未定义。
ItemSearch.vue
<script setup lang="ts">
import { lookUpItem } from '../systemApi'
async function getItemDetails() {
const response = await lookUpItem(mNumber, location)
}
</script>
systemAPI.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
}
你可以试试这个:
为了更好的阅读(和理解)
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;
}
}
当从 ItemSearch.vue 调用 lookUpItem 函数时,我得到未定义。
ItemSearch.vue
<script setup lang="ts">
import { lookUpItem } from '../systemApi'
async function getItemDetails() {
const response = await lookUpItem(mNumber, location)
}
</script>
systemAPI.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
}
你可以试试这个:
为了更好的阅读(和理解)
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;
}
}