【发布时间】:2019-02-12 19:10:17
【问题描述】:
我有一个在 React.js 上运行的网站前端。
我在 index.html 的 head 标签中添加了下面这行代码。
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
以下代码向我显示错误,“'adsbygoogle' is not defined no-undef”
componentDidMount () {
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-9142841210062390",
enable_page_level_ads: true
});
}
如何让广告显示在我的 React.js Web 应用程序上?
这适用于 Google 自动广告,而不是广告单元。
【问题讨论】:
-
@HardikModha Modha 正如我所指定的,将代码放在 componentDidMount() 中会导致我的问题。该帖子的解决方案对我没有帮助。我问的是自动广告,而不是广告单元。
-
这个错误看起来像一个 eslint 错误,你可以用
// eslint-disable no-undef禁用它