accelerated-mobile-page - 点击:AMP.setState 无法间歇性工作
问题描述
tap:AMP.setState 有时不工作,但当我重新加载页面时它工作。
<div class="padTop20">
<a [class]="model.nextStep.expand ? 'hide' : 'show'" role="button" class="show" on="tap:AMP.setState({model:{nextStep:{expand: true}}})" id="showmore">Show more</a>
<a [class]="model.nextStep.expand ? 'show' : 'hide'" role="button" class="hide" on="tap:AMP.setState({model:{nextStep:{expand: false}}})" id="showless">Show less</a>
</div>
这是我的默认状态:
<amp-state id="model">
<script type="application/json">
{
"nextStep":{
"expand":false
}
}
</script>
</amp-state>
是因为网络使它表现得像这样吗?感谢任何帮助!谢谢!
解决方案
你应该试试;
[class]="(model.nextStep.expand == 'true') ? 'hide' : 'show'"
和
[class]="(model.nextStep.expand == 'false') ? 'show' : 'hide'"
在页面加载时,一旦加载了 DOM,就会触发初始状态 (false),并且由于 amp-bind 而呈现 [class]。
您没有发布太多关于 AMP 可能遇到的控制台错误或验证错误(如果您做了一些奇怪/错误的事情,这将影响功能)
推荐阅读
- node.js - Flutter-node.js 对的最佳聊天框架?
- node.js - 在单个 Alexa 技能中使用多个声音?
- javascript - 如果可能,关闭所有打开的下拉菜单并合并代码
- node.js - 在多个服务器之间拆分 API 的负载
- html - 在 html (angular 6) 中附加一个带有对象属性的翻译字符串
- java - 代码审查:解决这个 java 程序的最佳方法是什么?
- reactjs - React:如何正确键入 HOC 组件?
- python - 硒 find_element_by_xpath
- windows - 如果 lastusetime 早于值,则删除帐户
- python - 使用 Tkinter 对象运行线程