简体   繁体   English

在Visual Studio中使用Polymer 3.0,以使用Iron-ajax进行休息

[英]Polymer 3.0 in visual studio to make rest call with iron-ajax

Hi I use visual studio 2017 with polymer 3.0.I try to use iron-ajax to rest call.But I take error 'Uncaught SyntaxError: Unexpected string iron-ajax line 11'.I copy same example at iron-ajax site but error is same.What I am missing about? 嗨,我将Visual Studio 2017与聚合物3.0结合使用。我尝试使用Iron-ajax进行剩余呼叫。但是我遇到了错误提示'Uncaught SyntaxError:Unexpected string iron-ajax line 11'。我在iron-ajax站点复制了相同的示例,但错误是一样。我缺少什么?

https://www.webcomponents.org/element/@polymer/iron-ajax https://www.webcomponents.org/element/@polymer/iron-ajax

> <script src="node_modules/@polymer/iron-ajax/iron-ajax.js"></script>
>     <script type="module">
>         import { PolymerElement, html } from './node_modules/@polymer/polymer/polymer-element.js';
>         //import './node_modules/@polymer/iron-ajax/iron-ajax.js';
>         class SampleElement extends PolymerElement {
>             static get template() {
>                 return html`
>       <iron-ajax
>           auto
>           url="http://localhost:8033/api/City/All"   
>           hande-as="json"
>           on-response="handleResponse"
>           debounce-duration="300">
>       </iron-ajax>
>     `;
>             }
>         }
> 
>             customElements.define('sample-element', SampleElement);
>     </script>

I tried to find out from your codes, but I could not find. 我试图从您的代码中查找,但找不到。 Maybe problems comes out from something else over there. 也许问题出在那边。 Here a working example: (I just changed the URL to retrieve some data: 这是一个工作示例:(我只是更改了URL来检索一些数据:

DEMO DEMO

import {PolymerElement, html} from '@polymer/polymer';

import '@polymer/iron-ajax/iron-ajax.js';
import '@polymer/iron-list/iron-list.js';
import '@polymer/iron-image/iron-image.js';

class SampleElement extends PolymerElement {
            static get properties() { return { 
                  response: { type: Object }
             }
            }
             static get template() {
                 return html`
               <iron-ajax 
                 auto id="ajax"
                 url="https://randomuser.me/api?results=10"
                 last-response="{{response}}"
                  on-response="handleResponse"
              > </iron-ajax>

                 <iron-list items="[[response.results]]" as="item" id="itemlist" scroll-target="document" selected-item="{{selectedItem}}" selection-enabled grid>
                 <template>
                       <div class = "flexchild" style="width:50%"> 
                        <iron-image   style ="width: 40px;height:40px; border-radius:30px;" src='[[item.picture.large]]'></iron-image> 
                        <span>[[item.name.first]] [[item.name.last]]</span>  </div><br/>
                  </template>
                  </iron-list>


                  `;
             }

     handleResponse(r) {
       console.log(r)
     }
  }
 customElements.define('sample-element', SampleElement);

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

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