AMP Show loading指示灯在Show More

时间:2018-09-03 14:45:11

标签: amp-html accelerated-mobile-page google-amp amp-list

我跟随this example在AMP上实施了“显示更多”操作。效果很好,但是当我单击按钮时,它没有显示任何内容,无法向用户提供页面正在加载的想法。

我的后端并不是特别快,所以直到负载加载后它似乎无法工作。

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')">

这只是示例中的内容,但有一些命名更改。

1 个答案:

答案 0 :(得分: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>
    
相关问题