vuepress build error: window is not defined
1.问题
在使用vuepress构建文档时,出现了如下问题:
2.原因
这是因为vuepress build生成的静态文件都是通过node服务端渲染完成的。因此,当组件中不是在beforeMount
或者 mounted
钩子中访问浏览器 / DOM 的 API时,就会有问题。
3.解决方法
对Markdown文件(.md)中引入的组件,使用内置的 <ClientOnly>
组件包裹。
如:
<ClientOnly><NonSSRFriendlyComponent/>
</ClientOnly>
但上述方法并不能解决对于组件中引入第三方组件库就访问浏览器api的问题,可使用es6提供的import的按需加载的功能。在组件的mounted钩子中使用。
<script>
export default {mounted () {// 当该组件挂载后,才会加载引入的模块import('./lib-that-access-window-on-import').then(module => {// use code})}
}
</script>
vuepress build error: window is not defined相关推荐
- 编写谷歌插件v3遇到“ReferenceError: window is not defined”错误
一.背景 得空学一下插件的编写Chrome Extensions.在GitHub找一些例子来看看,不过大多数都还是V2的,有些写法已经过时了,用不了.必须得对着文档来进行修改才行 练习的例子上,想写 ...
- 报错解决: error: this use of defined may not be portable
在编译grpc的时候报错如下: [HOSTCXX] Compiling src/compiler/cpp_generator.cc In file included from third_party/ ...
- 记个maven无法识别JAVA_HOME的问题 Error: JAVA_HOME is not defined correctly.
Error: JAVA_HOME is not defined correctly. We cannot execute /Library/Java/JavaVirtualMachines/jdk1. ...
- greta的问题及解决: LIBCMTD.lib(_wctype.obj) : error LNK2005: _iswspace already defined in xxx.obj...
greta,一个开源正则表达式模板库: http://research.microsoft.com/projects/greta/ 在debug unicode multithread dll的时候, ...
- 2021年1月19日工作日志 - Cypress regression tests build error
do you meet with Cypress regression tests build error? one example: https://travis-ci.com/github/SAP ...
- vuepress build提示YAMLException: end of the stream or a document separator is expected at line 7, colu
1.问题 vuePress执行build操作的时候 vuepress build ~/my_blogs/docs/ 错误提示如下 YAMLException: end of the stream or ...
- nuxt generate 报错 window is not defined
window id not defined 这是因为首先使用node服务端进渲染的,而node端不存在window对象 官方提供方法是在plugins里设置ssr 但是依然报错,后来找到了真正的原因 ...
- error ‘defineProps‘ is not defined no-undef
error 'defineProps' is not defined no-undef 例如defineProps和defineEmits生成no-undef警告 示例.eslintrc.js: mo ...
- Vue中:error ‘XXXXX‘ is not defined no-undef解决办法
Vue中:error 'XXXXX' is not defined no-undef解决办法 语法没错居然报错了 解决方法: 拓展 语法没错居然报错了 解决方法: 在使用vue的时候,使用一个全局变量 ...
最新文章
- 【笔记】大数定理证明
- Intel Realsense D435小车避障 摄像头在高于一定平面h时的深度map公式计算(深度d与视场角视角α的关系)
- SAP WebIDE Initialization process - 初始化逻辑分析
- 2014.3.5-C语言学习小结
- memory php 变量,php入门-变量
- 一个MySQL 5.7 分区表性能下降的案例分析
- Linux查看端口被那个进程占用
- android cpp 调用 shell命令
- CEGUI的安装简要总结
- After Effect CC 2019插件
- word文件怎么压缩?详细的操作步骤
- CSV文件打开乱码解决方法
- 如何使用 LK 字幕脚本工具
- Web前端大作业—个人网页(html+css+javascript)
- 构造和析构函数调用顺序
- 190822——喜欢
- SQL进阶教程—自链接的用法
- CIMPLICITY标签导入导出功能简单介绍
- 怎么在html文件中写css文件,html头文件中css怎么写?
- 【akka】akka源码 Akka源码分析-FSM