【发布时间】:2021-10-09 23:52:37
【问题描述】:
我有一个问题,不知道为什么我不能从另一个文件的函数中获取返回数据,我在这里尝试
我的文件.js
const psm = require("../services/psm");
psm.show(12).then((res) => console.log(res));
我的服务.js
const axios = require("../plugins/axios").default;
const module = "psm";
exports.show = async (payload) => {
await axios
.get(`/${module}/${payload}`)
.then((res) => {
return res.data.data;
})
.catch((err) => {
return Promise.reject(err.response);
})
.finally(() => {});
};
我得到undefined 返回..
【问题讨论】:
-
show不返回任何内容。 -
你能解释更多吗,我不是专家..
-
async..await 是 Promise 的语法糖。这里用错了。尽管它很有帮助,但我建议在您了解它的确切作用之前不要使用它。您将它们一起使用表明它是无缘无故的意外使用。
标签: javascript vue.js promise