【发布时间】:2018-01-24 16:51:48
【问题描述】:
我与 ReactJS 中的 Adsense 广告斗争了几个小时:
这是我的代码:
export default class AdJobDetail extends React.Component {
componentDidMount() {
(window.adsbygoogle = window.adsbygoogle || []).push({});
}
render() {
return (
<div className={style.container}>
<ins className='adsbygoogle'
style={{ display: 'display:block' }}
data-ad-client="ca-pub-6591684000448474"
data-ad-slot="6458345829"
data-ad-format="auto" />
</div>
);
}
}
(广告客户和广告位已更改)。
这是我使用的样式:
.container {
margin-top: 20px;
border: 1px solid $light-grey;
width: 200px;
height: 200px;
}
.ins {
width: 100%;
height: 100%;
}
我不断得到:
adsbygoogle.push() 错误:没有可用宽度=0 的槽大小
我的问题是:
- 对我来说,宽度大于 0,为什么会出现此错误?
- 会不会是脚本没有正确挂载?但是我的非响应式广告效果很好......
【问题讨论】:
-
您的 css 将
<ins />标记作为类.ins将其更改为ins或.adsbygoogle。