我需要将对象实例存储在我的动物数据库DB中,但是我无法在前面获取他的内容
我试图找出控制台日志的问题,但是...
这是我的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();
});
}
然后我使用console.log将此函数分配给组件中的var
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);
关于angular - 如何使用lambda函数访问Get请求的内容,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56461868/