【问题标题】:GatsbyJS - build show error window is not defined (AOS)GatsbyJS - 构建显示错误窗口未定义(AOS)
【发布时间】:2018-01-06 13:50:20
【问题描述】:

我是 GatsbyJS 和 ReactJS 的新手,我在构建项目时遇到了问题。 问题是每当我在其中构建带有 AOS 的项目时,它都会显示错误窗口未定义。在开发模式下运行完全没问题。

这是我的代码:

我读到 componentDidMount() 应该可以解决问题。不幸的是,它对我不起作用。

有什么帮助吗?谢谢。。

【问题讨论】:

    标签: javascript reactjs animate.css gatsby


    【解决方案1】:

    我将代码更改为:

    import React from "react";
    import Link from "gatsby-link";
    
    import whiteLogo from "../img/tm_logo_white.png";
    import myImg from "../img/me.jpg";
    
    class IndexPage extends React.Component {
    
        componentDidMount() {
            const isBrowser = typeof window !== "undefined";
            const AOS = isBrowser ? require("aos") : undefined;
    
            this.aos = AOS;
            this.aos.init();
        }
    
        componentDidUpdate() {
            this.aos.refresh();
        }
    }
    
    

    删除了顶部的import AOS from "aos",一切正常。

    【讨论】:

    • 不错,但将来可能会使用代码而不是图像!
    猜你喜欢
    • 1970-01-01
    • 2021-11-25
    • 2021-08-16
    • 1970-01-01
    • 2021-06-30
    • 2017-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多