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相关推荐

  1. 编写谷歌插件v3遇到“ReferenceError: window is not defined”错误

    一.背景 得空学一下插件的编写Chrome  Extensions.在GitHub找一些例子来看看,不过大多数都还是V2的,有些写法已经过时了,用不了.必须得对着文档来进行修改才行 练习的例子上,想写 ...

  2. 报错解决: error: this use of defined may not be portable

    在编译grpc的时候报错如下: [HOSTCXX] Compiling src/compiler/cpp_generator.cc In file included from third_party/ ...

  3. 记个maven无法识别JAVA_HOME的问题 Error: JAVA_HOME is not defined correctly.

    Error: JAVA_HOME is not defined correctly. We cannot execute /Library/Java/JavaVirtualMachines/jdk1. ...

  4. greta的问题及解决: LIBCMTD.lib(_wctype.obj) : error LNK2005: _iswspace already defined in xxx.obj...

    greta,一个开源正则表达式模板库: http://research.microsoft.com/projects/greta/ 在debug unicode multithread dll的时候, ...

  5. 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 ...

  6. 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 ...

  7. nuxt generate 报错 window is not defined

    window id not defined 这是因为首先使用node服务端进渲染的,而node端不存在window对象 官方提供方法是在plugins里设置ssr 但是依然报错,后来找到了真正的原因 ...

  8. error ‘defineProps‘ is not defined no-undef

    error 'defineProps' is not defined no-undef 例如defineProps和defineEmits生成no-undef警告 示例.eslintrc.js: mo ...

  9. Vue中:error ‘XXXXX‘ is not defined no-undef解决办法

    Vue中:error 'XXXXX' is not defined no-undef解决办法 语法没错居然报错了 解决方法: 拓展 语法没错居然报错了 解决方法: 在使用vue的时候,使用一个全局变量 ...

最新文章

  1. 【笔记】大数定理证明
  2. Intel Realsense D435小车避障 摄像头在高于一定平面h时的深度map公式计算(深度d与视场角视角α的关系)
  3. SAP WebIDE Initialization process - 初始化逻辑分析
  4. 2014.3.5-C语言学习小结
  5. memory php 变量,php入门-变量
  6. 一个MySQL 5.7 分区表性能下降的案例分析
  7. Linux查看端口被那个进程占用
  8. android cpp 调用 shell命令
  9. CEGUI的安装简要总结
  10. After Effect CC 2019插件
  11. word文件怎么压缩?详细的操作步骤
  12. CSV文件打开乱码解决方法
  13. 如何使用 LK 字幕脚本工具
  14. Web前端大作业—个人网页(html+css+javascript)
  15. 构造和析构函数调用顺序
  16. 190822——喜欢
  17. SQL进阶教程—自链接的用法
  18. CIMPLICITY标签导入导出功能简单介绍
  19. 怎么在html文件中写css文件,html头文件中css怎么写?
  20. 【akka】akka源码 Akka源码分析-FSM

热门文章

  1. 给老师发邮件的格式参考
  2. RK3588 烧写固件
  3. windows server2008 设置允许特定端口通过防火墙
  4. 安卓音视频入门难,老司机分享音视频开发学习技巧与痛点
  5. 【笔记】识别手写数字神经网络
  6. 使用模板消息及利用模板消息群发的说明
  7. su与su - 命令详解
  8. [日更-2019.4.26、27、28] cm-14.1 Android系统启动过程分析(四)-应用程序进程启动过程...
  9. 如何运行app和exe程序
  10. 势哨乜池略撑滋度墓泵乜琴剐砂倒