AMP显示加载指示器显示更多

问题描述 投票:1回答:1

我跟着this example在AMP上实施了“Show More”行动。它工作得很好,但是当我点击按钮时,它不会显示任何内容,以便让用户知道页面正在加载。

我的后端并不是特别快,所以看起来它不起作用,直到最终,事情加载。

the demo它也没有任何东西,但它超级快。

什么都可以做?即使它只是禁用按钮。我没有看到列表或表单上的任何类更改,以便在CSS上使用它们。

这是我的代码:

amp-state id="#{section}State" src="#{path}"
amp-state id="#{section}"
  script type="application/json"
    | {
    | "page": 2,
    | "hasMorePages": true
    | }
|<amp-list src="#{path}" layout="responsive" height="600px" width="600px" [src]="#{section}State.items" [height]="(#{section}State.items.length / 3) * 400">
template[type="amp-mustache"]
  = render partial: item_template, locals: { image: image }
|</amp-list>
form method="GET" action="#{path}" action-xhr="#{path}" target="_top" on="submit-success: AMP.setState({ #{section}State: { items: #{section}State.items.concat(event.response.items) }, #{section}: { page: #{section}.page + 1, hasMorePages: event.response.hasMorePages } });" novalidate=""
  |<input type="hidden" name="page" value="2" [value]="#{section}.page">
  |<input type="submit"
         value="Show more"
         class="show-more"
         [class] = "(#{section}.hasMorePages == false ? 'hide' : 'ampstart-btn caps m1 mb3 show show-more')">

它只是示例中的一个,有一些命名更改。

amp-html accelerated-mobile-page google-amp amp-list
1个回答
1
投票

在表单提交上显示加载指示符有两种付款方式:

  1. 使用amp-form的内置submitting状态: <form ...> ... <button>Show more</button> ... <div submitting> Loading... </div> </form>
  2. 如果您需要更大的灵活性,可以在amp-state变量中跟踪表单状态,例如: myFormState,然后在不同的表单提交事件上更新。根据变量,您可以隐藏并在页面上显示不同的元素: <form on="submit: AMP.setState( { myFormState: 'submitting' } ), submit-success: AMP.setState( { myFormState: 'success' } ), submit-error: AMP.setState( { myFormState: 'error' } ) " ... > <amp-list [hidden]="myFormState != 'success'" ... > ... </amp-list> <div hidden [hidden]="myFormState != 'submitting'" ...>Loading</div> <div hidden [hidden]="myFormState != 'error'" ...>Something went wrong :-(</div>
© www.soinside.com 2019 - 2024. All rights reserved.