问题描述
我使用的是 Nuxt 2.13,但遇到了 window.__Nuxt__(function(a,b,c,d,.....))
问题。我不知道它是否会影响我的 SEO,但它让我很紧张,并显示了我所有的语言文件。
情况如下:我的应用中有一个 lang.json
文件。我阅读了它并将其存储在 lang
中的 Vuex
状态。但是 window.__Nuxt__
显示了我不想显示的语言!!
1:通过将此代码添加到 nuxt.config.js link to stack answer
hooks: {
'vue-renderer:ssr:context'(context) {
const routePath = JSON.stringify(context.nuxt.routePath);
context.nuxt = {serverRendered: true,routePath};
}
}
}
2:通过注释node_module/@nuxt/vue-renderer/dist/vue-renderer.js
中的一些代码
link to article
3:通过使用cheerio包并从正文中抓取脚本 link to article
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()
}
}
}
这三个都可以完成工作,但是!!我的组件将不再被延迟加载,因为我在 Vuex 中使用状态来为延迟加载提供主题地址!例如:
computed:{
mycomponent(){
return ()=>import(`~/components/${this.$store.state.siteDirection}/mycomp.vue`)
}
}
当 this.$store.state.siteDirection
为 null 时,webpack 无法延迟加载它会报错。
我该如何解决这个问题??
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)