如何从 Nuxt 中的 Vuex 中删除 window.__NUXT__ 没有任何问题

Moj*_*ari 5 vuex vuejs2 nuxt.js vue-render-function

我在 Nuxt 2.13 上遇到了window.__Nuxt__(function(a,b,c,d,.....)). 我不知道它是否会影响我的 SEO,但它让我很紧张,并显示了我所有的语言文件。

这是情况:lang.json我的应用程序中有一个文件。我阅读了它并将其存储langVuex. 但window.__Nuxt__显示了我不想要的语言!!

到目前为止,我已经找到了三个解决方案来删除它:

1:通过将此代码添加到 nuxt.config.js 链接到堆栈答案

hooks: {
    'vue-renderer:ssr:context'(context) {
      const routePath = JSON.stringify(context.nuxt.routePath);
      context.nuxt = {serverRendered: true, routePath};
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

2:通过评论文章链接中的一些代码node_module/@nuxt/vue-renderer/dist/vue-renderer.js

3:通过使用cheerio包并将脚本从正文链接抓取 到文章

const cherrio = const cheerio = require('cheerio');
export default {
//The rest configuration is omitted
hooks: {
    'render:route': (url, result) => {
      this.$ = cheerio.load(result.html,{decodeEntities: false});
      //Since window.__nuxt__ is always located in the first script in the body,
      //So I removed the first script tag in the body
      this.$(`body script`).eq(0).remove();
      result.html = this.$.html()
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

这三个都可以完成这项工作,但是!!我的组件将不再被延迟加载,因为我在 Vuex 中使用状态来为延迟加载提供主题地址!例如:

computed:{
  mycomponent(){
    return ()=>import(`~/components/${this.$store.state.siteDirection}/mycomp.vue`)
  }
}
Run Code Online (Sandbox Code Playgroud)

它会给出错误,即 webpack 无法将其延迟加载为this.$store.state.siteDirectionnull。

我该如何解决这个问题??