简体   繁体   English

聚合物铁ajax无法正常工作

[英]Polymer iron-ajax not working

I'm testing Polymer's iron-ajax calls. 我正在测试Polymer的iron-ajax电话。 For this, I set up a dummy view: 为此,我设置了一个虚拟视图:

<link rel="import" href="../bower_components/polymer/polymer-element.html">
<link rel="import" href="shared-styles.html">
<link rel="import" href="../bower_components/iron-flex-layout/iron-flex-layout-classes.html">

<dom-module id="my-voltage">
  <template is="auto-binding">
  <style include="shared-styles iron-flex iron-flex-alignment">
  .circle {
    display: inline-block;
    text-align:center;
    color: black;
    border-radius: 70%;
    background: #ddd;
    font-size: 30px;
    width: 110px;
    height: 110px;
    margin: 15px;
  }
  </style>
        <iron-ajax id="ajax"
                   auto
                   url="https://jsonplaceholder.typicode.com/posts/1"
                   last-response="{{data}}"
                   on-response="_onResponse"
                   handleAs="json">
        </iron-ajax>
        <div class="circle">{{data.id}}</div>
    </template>
  <script>
    class MyVoltage extends Polymer.Element {
      static get is() {
        return "my-voltage";
      }

      _onResponse() {
        setTimeout(() => this.$.ajax.generateRequest(), 500);
      }
    }
    customElements.define(MyVoltage.is, MyVoltage);
  </script>
</dom-module>

This, however, doesn't work. 但是,这不起作用。 I want to ping the API every half a second, but it's not even loading once: I'm just getting an empty circle. 我想每半秒钟对API进行一次ping操作,但它甚至没有加载一次:我只是空了一个圈。 在此处输入图片说明

What am I missing here? 我在这里想念什么? Why doesn't the API call work? 为什么API调用无效? Thank you! 谢谢!

Well the first thing that comes in mind is that you forgot to import it? 那么首先想到的是您忘记了导入它? Depending on the code you shared you only import polymer-element, shared-style and iron-flex-layout-classes. 根据您共享的代码,您仅导入聚合物元素,共享样式和iron-flex-layout类。 Next thing i see is that the handleAs param must be written as handle-as since html does not care about camel cases 我看到的下一件事是,必须将handleAs参数编写为handle-as,因为html并不关心骆驼的情况

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

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