vuejs2 - 如何从 Nuxt 中的 Vuex 中删除 window.__NUXT__ 而不会出现任何问题
问题描述
我在 Nuxt 2.13 上,我遇到了window.__Nuxt__(function(a,b,c,d,.....))
. 我不知道它是否会影响我的 SEO,但它让我很紧张,并显示了我所有的语言文件。
这是情况:lang.json
我的应用程序中有一个文件。我阅读它并将其存储lang
在Vuex
. 但window.__Nuxt__
显示我不想的语言!
到目前为止,我已经找到了三种解决方案来删除它:
1:通过将此代码添加到 nuxt.config.js 链接到堆栈答案
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
文章链接中的一些代码
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()
}
}
}
这三个人都会完成这项工作,但是!我的组件将不再延迟加载,因为我使用 Vuex 中的状态来为延迟加载提供主题地址!例如:
computed:{
mycomponent(){
return ()=>import(`~/components/${this.$store.state.siteDirection}/mycomp.vue`)
}
}
它会给出错误 webpack 不能延迟加载 this 为this.$store.state.siteDirection
空。
我该如何解决这个问题?
解决方案
推荐阅读
- android - Xamarin 形成日期选择器绑定日期并在日期更改时执行某些操作
- javascript - 如何使用javascript根据另一个div元素的位置放置弹出窗口并做出反应?
- jsf - Primefaces Datatable过滤问题,用于下拉作为数据输入
- angular - 角度错误 TS2339 属性在类型上不存在
- sql - 在其他条件下查找 MIN 值 Teradata
- python - 获取 matplotlib 分散的 3D 点以按 3 个数组的乘积显示颜色
- c# - 堆叠 WPF 窗口
- c# - C# Mongo 序列化问题
- react-native - 如何在 React Native 中设置根视图的背景?
- php - 与整数中的 PHP 相比,如何在 Python 中使用逻辑运算符?