我的 faunadb 数据库中有一个值,我想在单击按钮时将其增加 1。
我不知道该怎么做
我试过这个:
const change = (data) => {
return fetch(`/.netlify/functions/todos-update`, {
body: JSON.stringify(data),
method: 'POST'
}).then(response => {
return response.json()
})
}
Run Code Online (Sandbox Code Playgroud)
并用这个触发它
var dataa = document.getElementById('amount').innerHTML
change(("value: " + dataa))
Run Code Online (Sandbox Code Playgroud)
我的服务器端代码是这样的:
exports.handler = (event, context, callback) => {
const data = JSON.parse(event.body)
const id = "236323245287014920"
console.log(`Function 'todo-update' invoked. update id: ${id}`)
return client.query(q.Update(q.Ref(`classes/nappi/${id}`), {data}))
.then((response) => {
console.log('success', response)
return callback(null, {
statusCode: 200,
body: JSON.stringify(response)
})
}).catch((error) => {
console.log('error', error)
return callback(null, …Run Code Online (Sandbox Code Playgroud)