简体   繁体   English

从 axios function 得到回应

[英]Getting response from axios function

When calling the lookUpItem function from ItemSearch.vue I get undefined.从 ItemSearch.vue 调用 lookUpItem function 时,我得到了未定义。

ItemSearch.vue项目搜索.vue

   <script setup lang="ts">
      import { lookUpItem } from '../systemApi'

      async function getItemDetails() {
         const response = await lookUpItem(mNumber, location)      
}
   </script>

systemAPI.ts系统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
}

You could try this:你可以试试这个:

For better reading (and understanding)为了更好地阅读(和理解)

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;
  }
}
  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM