- Create
exception.js
inplugins
directory (see exception.js) - Add
@/plugins/exception
intoplugins
array ofnuxt.config.js
- Use
app.$exception
function instead oferror
function inasyncData
Example: pages/index.vue
export default {
async asyncData({ app }) {
try {
const asyncData = {}
asyncData.posts = await app.$axios.$get('/posts')
return asyncData
} catch(e) {
app.$exception(e)
}
}
}
More docs about Nuxt error