Polymer - 如何覆盖计算属性?

时间:2017-12-02 20:03:38

标签: polymer

如何覆盖计算属性?

这是一个片段,其中父类A计算result属性等于value属性,而其子类B重新< / strong>将result属性计算为等于value + value2

但覆盖不起作用......

  class A extends Polymer.Element {    
    static get properties(){
      return {
        value : Number,
        
        result : {
          type : Number,
          computed : "computeProperty(value)"
        }
      }
    }
    
    computeProperty(value){
      return value;
    }
  }
  
  class B extends A {
    static get is() { return "b-element"; }
    
    static get template(){
      return `
        <div>Value : [[value]]</div>
        <div>Value2 : [[value2]]</div>
        <div>Result : [[result]]</div>
      `
    }
    
    static get properties(){
      return {
        value2 : Number,
        
        result : {
          type : Number,
          computed : "recomputeProperty(value, value2)"
        }
      }
    }
    
    recomputeProperty(value, value2){
      return value + value2;
    }
  }
  
  
  // Register the new element with the browser
  customElements.define(B.is, B);
<script src="https://polygit.org/components/webcomponentsjs/webcomponents-loader.js"></script>
<link rel="import"  href="https://polygit.org/components/polymer/polymer-element.html">

  <b-element value="1" value2="2">
  </b-element>

0 个答案:

没有答案