2017-07-18 6 views
0

私はPolymerのiron-ajaxコールをテストしています。このため、ダミービューを設定しました。ポリマーアイアンアヤックスが作動しない

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

これは機能しません。私はAPIを0.5秒ごとにpingしたいのですが、一度読み込まなくても、私は空のサークルを手に入れています。 enter image description here

私はここで何が欠けていますか? API呼び出しが機能しないのはなぜですか?ありがとうございました!

答えて

0

最初に覚えておいていただきたいのは、インポートを忘れたことです。共有するコードによっては、ポリマー要素、共有スタイル、および鉄フレックスレイアウトクラスだけをインポートすることができます。 次に見られるのは、htmlはラクダのケースを気にしないので、handleAsのparamはハンドルとして記述する必要があるということです。