【发布时间】:2018-01-06 13:50:20
【问题描述】:
我是 GatsbyJS 和 ReactJS 的新手,我在构建项目时遇到了问题。 问题是每当我在其中构建带有 AOS 的项目时,它都会显示错误窗口未定义。在开发模式下运行完全没问题。
这是我的代码:
我读到 componentDidMount() 应该可以解决问题。不幸的是,它对我不起作用。
有什么帮助吗?谢谢。。
【问题讨论】:
标签: javascript reactjs animate.css gatsby
我是 GatsbyJS 和 ReactJS 的新手,我在构建项目时遇到了问题。 问题是每当我在其中构建带有 AOS 的项目时,它都会显示错误窗口未定义。在开发模式下运行完全没问题。
这是我的代码:
我读到 componentDidMount() 应该可以解决问题。不幸的是,它对我不起作用。
有什么帮助吗?谢谢。。
【问题讨论】:
标签: javascript reactjs animate.css gatsby
我将代码更改为:
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",一切正常。
【讨论】: