[英]error: syntax error at or near “$”
我目前正在檢查Vue,並對個人項目進行一些重構。
我的API遇到了一些問題。
涉及的兩種技術是axios ,我正在使用axios將請求發送到我的API,該API使用pg-promise與postgres數據庫進行通信。
api調用...
function add (entry, cb) {
const length = entry.content.length
entry.title = `${entry.content.substring(0, 32)}`
axios.post('/api/notes', entry).then(cb)
}
在這里,輸入項和對象{標題,內容,優先級,狀態,上下文}
pg-promise端點
export const createNote = (req, res, next) => {
db.none('insert into entries(title, content, prio, status, context)' +
'values( ${title}, ${content}, ${prio}, ${status}, ${context})',
req.body)
.then(() => {
res.status(200)
.json({
status: 'success',
message: 'Inserted one entry'
})
}).catch(err => next(err))
}
在這里,req.body是未定義的
我正在閱讀axios上的文檔,似乎無法找到我的api調用有什么問題,以為我會在這里發布一些內容。
謝謝!
req.body它具有以下結構[{.....}]
對於pg-promise需要{....}
問題req.body [0]的解決方案
export const createNote = (req, res, next) => {
db.none('insert into entries(title, content, prio, status, context)' +
'values( ${title}, ${content}, ${prio}, ${status}, ${context})',
req.body[0])
.then(() => {
res.status(200)
.json({
status: 'success',
message: 'Inserted one entry'
})
}).catch(err => next(err))
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.