[英]Getting the Axios response from inside the pipe function in javascript
[英]Getting response from axios function
从 ItemSearch.vue 调用 lookUpItem function 时,我得到了未定义。
项目搜索.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
}
你可以试试这个:
为了更好地阅读(和理解)
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.