[英]Nuxt.js Server side plugin function is not a function
I created a server side plugin and I'm getting 我创建了一个服务器端插件,
context.app.handleServerError is not a function context.app.handleServerError不是函数
// hanlde-server-error.js // hanlde-server-error.js
export default ({ app }, inject) => {
app.handleServerError = (method, error, data) => {
const message = `An error occured in ${method}. ${error}`
console.error(message)
Sentry.captureException(new Error(message))
}
}
// nuxt.config.js // nuxt.config.js
plugins: [
{ src: '~plugins/handle-server-error', mode: 'server' },
],
// calling function //调用函数
async asyncData(context) {
// await store.dispatch('fetchAccounts')
try {
await undefinedFunction()
} catch (error) {
context.app.handleServerError('asyncData', error, { user: 'bambam' })
}
},
Am I correct that asyncData makes the call server side? 我是否正确说asyncData成为呼叫服务器端? According to the docs this function should be available on context. 根据文档,此功能应在上下文中可用。
Execute it only server side. 仅在服务器端执行它。
async asyncData(context) {
if (process.server) {
try {
await undefinedFunction()
} catch (error) {
context.app.handleServerError('asyncData', error, { user: 'bambam' })
}
}
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.