如何解决当我在模板中包含一个本地 .js 文件时,Vue 拒绝构建,该文件引用了“window”全局 - ReferenceError: window is not defined
我有一个 VuePress 项目,我只需要在图库的组件中包含一个本地 js 文件。 .js 文件正在引用 window 对象,而我的项目拒绝构建:
(node:57059) UnhandledPromiseRejectionWarning: ReferenceError: window is not defined
at isMobile (4.server-bundle.js:1470:27)
at 4.server-bundle.js:3343:20
at 4.server-bundle.js:937:109
at Object.345 (4.server-bundle.js:942:3)
at __webpack_require__ (server-bundle.js:27:30)
at Module.356 (4.server-bundle.js:5022:17)
at __webpack_require__ (server-bundle.js:27:30)
(node:57059) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block,or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection,use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 49)
(node:57059) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
从文档中我了解到我只应该在 window
生命周期方法中引用 mounted
。但是其他脚本呢?我该如何处理?
这是我如何包含脚本:
</template>
<script>
import * as GLightbox from '../assets/scripts/glightbox.js'
export default {
// ...
这是我使用它的方式:
// ...
mounted: function () {
this.lightbox = GLightbox({
touchNavigation: true,loop: true
})
},
干杯
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。