angular - 如何使用 lambda 函数访问我的 Get 请求的内容
问题描述
我需要将对象实例存储在我的动物区数据库中,但我无法将他的内容放在我的前面
我试图找出控制台日志的问题,但是......
这是我的 lambda 函数
/* code from functions/todos-read.js */
import faunadb from 'faunadb'
const q = faunadb.query
const client = new faunadb.Client({
secret: process.env.FAUNADB_SECRET
})
exports.handler = (event, context, callback) => {
const id = '234316534878568967'
console.log(`Function 'todo-read' invoked. Read id: ${id}`)
return client.query(q.Get(q.Ref(q.Class("missions"), "234316534878568967")))
.then((response) => {
console.log("success", response)
return callback(null, {
statusCode: 200,
body: JSON.stringify(response)
})
}).catch((error) => {
console.log("error", error)
return callback(null, {
statusCode: 400,
body: JSON.stringify(error)
})
})
}
我在我的角度服务中的功能:
readById = () => {
return fetch('/.netlify/functions/mission-read-by-id').then((response) => {
console.log(response);
return response.json();
});
}
然后我将此函数分配给我的组件中的一个var,带有一个console.log
this.missionData = this.missionService.readById();
console.log(this.missionData);
控制台响应结果:
[BACK] [LAMBDA] Request from ::ffff:127.0.0.1: GET /mission-read-by-id
[BACK] [LAMBDA] Function 'todo-read' invoked. Read id: 234316534878568967
[BACK] [LAMBDA] success { ref: Ref(Class("missions"), "234316534878568967"),
[BACK] [LAMBDA] ts: 1559720511260000,
[BACK] [LAMBDA] data:
[BACK] [LAMBDA] { consultant: 'sd',
[BACK] [LAMBDA] consultantEmail: 'sdq@gg.com' } }
[BACK] [LAMBDA] Response with status 200 in 256 ms.
console.log 组件的结果:
{…}
__zone_symbol__state: true
__zone_symbol__value: {…}
data: {…}
client: "dvs"
clientEmail: "sdq@gg.com"
<prototype>: Object { … }
ref: Object { "@ref": {…} }
ts: 1559720511260000
<prototype>: Object { … }
<prototype>: Object { then: then(), catch: catch(), finally: finally(), … }
我不明白如何得到我的对象,那么如果你能解释我......非常感谢
解决方案
readById
正在返回一个所以,Promise
您需要更改代码以使用它:
this.missionService.readById().then(missionData => console.log(missionData))
// or using async/await
this.missionData = await this.missionService.readById();
console.log(this.missionData);
推荐阅读
- sql - Oracle XMLCONCAT 将结果分配给变量
- excel - 如何检查读入 VBA 日期的空字段
- javascript - 如何使这些按钮正常工作
- javascript - VueJS 在 v-for 中只选择一个元素
- python-2.7 - 如何限制用户在不发布日记帐的情况下创建和编辑会计日记帐,以及如何在 odoo 10 中创建另一个用户发布日记帐
- python - python代码-费率计算。我怎样才能使这段代码正确?
- c++ - 在 Qt5 中为高 DPI 缩放图像的最佳方法是什么?
- .net - 将 .NET 控制台应用程序编译为单个可执行文件
- javascript - 表单提交后如何检查电子邮件是否已存在
- c++ - 语言环境是否有定义负符号的构面?