我有这样的放大器状态:
<amp-state id="smartBannerData">
<script type="application/json">
{
"0": {
"imgSrc": "https://cdn.voicetube.com/assets/img/banners/smartbanner-jp-20200116.jpg"
},
"1": {
"imgSrc": "https://cdn.voicetube.com/assets/img/banners/smartbanner-branding-jp.jpg"
}
}
</script>
</amp-state>
<amp-img
alt=""
src="https://cdn.voicetube.com/assets/img/banners/smartbanner-jp-191205.png"
width="500"
height="100"
layout="responsive"
[src]="smartBannerData[currentImg].imgSrc"
>
</amp-img>
<button on="tap:AMP.setState({currentImg: '0'})">1</button>
<button on="tap:AMP.setState({currentImg: '1'})">2</button>
如果我单击按钮,图像将动态变化。我想在加载页面时随机更改 imgSrc:
<amp-script script="smart-banner">
<p>
test
</p>
</amp-script>
<script id="smart-banner" type="text/plain" target="amp-script">
setTimeout(function(){ AMP.setState({currentImg: '1'}); }, 2000)
</script>
但图像不会改变..我是 AMP 的新手,有人可以帮我解决问题吗?