Polymer 如何处理聚合物中可以是字符串或对象的属性?

Polymer 如何处理聚合物中可以是字符串或对象的属性?,polymer,web-component,mapbox-gl-js,polymer-2.x,Polymer,Web Component,Mapbox Gl Js,Polymer 2.x,我正在尝试创建一个聚合物网络组件 我想使用聚合自定义元素上的属性设置“圆形颜色绘制”属性(),但该属性可以是字符串或对象,请参见: "circle-color": "#ff0" 或者对于数据驱动的属性 "circle-color": { "property": "temperature", "stops": [ // "temperature" is 0 -> circle color will be blue [0, 'blue'],

我正在尝试创建一个聚合物网络组件

我想使用聚合自定义元素上的属性设置“圆形颜色绘制”属性(),但该属性可以是字符串或对象,请参见:

"circle-color": "#ff0"
或者对于数据驱动的属性

"circle-color": {
    "property": "temperature",
    "stops": [

      // "temperature" is 0   -> circle color will be blue
      [0, 'blue'],

      // "temperature" is 100 -> circle color will be red
      [100, 'red']

    ]
  }
那么,我应该在聚合物组分的属性函数中使用什么呢?字符串还是对象

class XCustom extends Polymer.Element {

  static get properties() {
    return {
      circle-color: String,
      // or circle-color: Object ?
    }
  }
}

customElements.define('x-custom', XCustom);

谢谢你的帮助!(我已经检查过了,它不起作用)

真的没关系。您可以同时存储这两个变量,但为了清晰起见,请将其存储为对象,如果变量是字符串,则将其存储为对象。

这并不重要。您可以同时存储这两个变量,但为了清晰起见,请将其存储为对象,如果变量是字符串,则将其转换为对象