From cf3e879aa58fb88800b968386e77d68b8bc02fb7 Mon Sep 17 00:00:00 2001 From: nickfrosty <75431177+nickfrosty@users.noreply.github.com> Date: Sun, 12 Dec 2021 08:44:38 -0500 Subject: [PATCH] fix(asyncData): $nuxt undefined fix fixes the `$nuxt undefined` error for newer versions of nuxt Closes #5 --- package/lib/plugin.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/package/lib/plugin.js b/package/lib/plugin.js index 368c50c..5232074 100644 --- a/package/lib/plugin.js +++ b/package/lib/plugin.js @@ -23,13 +23,18 @@ export default function (ctx, inject) { ctx.app.context.app.head = ctx.app.head } - if (Vue.prototype && Vue.prototype.$meta) { // Vue-meta is enabled - if (this.$nuxt && this.$nuxt.$options && this.$nuxt.$options.head) { - this.$nuxt.$options.head = ctx.app.head - } else if (Vue.prototype.$nuxt && Vue.prototype.$nuxt.$options && Vue.prototype.$nuxt.$options.head) { - Vue.prototype.$nuxt.$options.head = ctx.app.head + try { + if (Vue.prototype && Vue.prototype.$meta) { // Vue-meta is enabled + if (this.$nuxt && this.$nuxt.$options && this.$nuxt.$options.head) { + this.$nuxt.$options.head = ctx.app.head + } else if (Vue.prototype.$nuxt && Vue.prototype.$nuxt.$options && Vue.prototype.$nuxt.$options.head) { + Vue.prototype.$nuxt.$options.head = ctx.app.head + } } } + catch ( err ){ + // unable to parse vue head + } deb('HEAD:', ctx.app.head) return ctx.app.head