Polymer 3 Element - NotSupportedError

问题描述 投票:0回答:1

我已经开始使用Polymer 3.0入门教程并决定使用它。我已经开始了一个新项目,我正在尝试将paper-dropdown-menu添加到view1中,以便从数组中获取数据。

view1.js:

/**
 * @license
 * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
 * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
 * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
 * Code distributed by Google as part of the polymer project is also
 * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
 */

import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
import './shared-styles.js';
import './car-make.js'

class MyView1 extends PolymerElement {
  static get template() {
    return html`
      <style include="shared-styles">
        :host {
          display: block;

          padding: 10px;
        }
      </style>

      <div class="card">
        <div class="circle">1</div>
        <h1>View One</h1>
        <car-make></car-make>
      </div>
    `;
  }
}

window.customElements.define('my-view1', MyView1);

我创建了一个可以做到这一点的元素,当我运行演示时它工作得很好

car-make.js元素:

import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
import {} from '@polymer/polymer/lib/elements/dom-repeat.js';
import '@polymer/paper-dropdown-menu/paper-dropdown-menu.js';
import '@polymer/paper-item/paper-item.js';
import '@polymer/paper-listbox/paper-listbox.js';
/**
 * `car-make`
 * Car manufacturers dropdown
 *
 * @customElement
 * @polymer
 * @demo demo/index.html
 */


class CarMake extends PolymerElement {
  static get template() {
    return html`
      <style>
        :host {
          display: block;
        }
      </style>
      <paper-dropdown-menu label="Car manufacturer">
        <paper-listbox slot="dropdown-content" required>
        <template is="dom-repeat" items="{{cars}}">
            <paper-item>{{item}}</paper-item>
        </template>
        </paper-listbox>
      </paper-dropdown-menu>
    `;
  }
  static get properties() {
    return {
      cars: {
        type: Array,
        value: getCars(),
      }
    };
  }
  constructor() {
    super();
  }
}
function getCars() {
  return ['AC', 'ALPINA', 'Abarth'];
}
window.customElements.define('car-make', CarMake);

但是当NotSupportedError: Operation is not supportedpolymer-fn.js行触发49时,它总是失败,当我将它添加到my-view1.js时:

customElements.define(klass.is,
    /** @type {!HTMLElement} */
    klass);
    return klass

这是触发错误的函数。我究竟做错了什么?

javascript polymer paper-elements
1个回答
0
投票

在属性样式下定义汽车值是错误的,而是使用:

static get properties() {
    return {
      cars: {
        type: Array

      }
    };
  }
  constructor() {
    super();
    this.cars=['AC', 'ALPINA', 'Abarth' ];
  }

这里Demo(它正在工作,但可能会给出额外依赖的错误。(只是为了激发它)

© www.soinside.com 2019 - 2024. All rights reserved.