简体   繁体   English

AMP 在 Show More 上显示加载指示器

[英]AMP show loading indicator on Show More

I followed this example to implement a "Show More" action on AMP.我按照此示例在 AMP 上实施“显示更多”操作。 It's working great but when I click on the button it doesn't display anything to give the user the idea that the page is loading.它工作得很好,但是当我点击按钮时,它没有显示任何内容让用户认为页面正在加载。

My backend isn't particularly fast and so it looks like it didn't work until, eventually, things load.我的后端不是特别快,所以看起来它直到最终加载时才起作用。

In the demo it doesn't have anything either, but it's super fast.演示中,它也没有任何内容,但速度非常快。

Can anything be done?有什么可以做的吗? Even if it's just disabling the button.即使它只是禁用按钮。 I don't see any class changes on the list or form as to use them on the CSS.我在列表或表单上没有看到任何类更改,以便在 CSS 上使用它们。

This is my code:这是我的代码:

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

It's just the one from the example with a few naming changes.这只是示例中的一个,但进行了一些命名更改。

There are two pays to show a loading indicator on form submission:在表单提交时显示加载指示器有两种支付方式:

  1. Use amp-form 's built-in submitting state:使用amp-form的内置submitting状态:

     <form ...> ... <button>Show more</button> ... <div submitting> Loading... </div> </form>
  2. If you need more flexibility you can keep track of the form state in an amp-state variable, eg myFormState , which is then updated on the different form submit events.如果您需要更大的灵活性,您可以在amp-state变量中跟踪表单状态,例如myFormState ,然后在不同的表单提交事件上更新。 Based on the variable you can then hide and show different elements on your page:根据变量,您可以在页面上隐藏和显示不同的元素:

     <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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM