【问题标题】:change property value in polymer改变聚合物的属性值
【发布时间】:2017-12-21 00:52:50
【问题描述】:

我已经声明了这样一个属性:

static get properties() {
        return {
            auth1: {
                type: Boolean,
                readonly: false,
                value: false,
                notify: true
            }
        };
    }

在我的 Polymer 元素中。现在我有了这个功能:

connect(){
        this.auth1.value = true;
        console.log("Authenticated" + this.authenticated);

    }

这应该将属性值更改为 true。每次我调用该函数时,我都会遇到错误“TypeError: Attempted to assign to readonly property.”。但是我在我的属性中将 readonly 设置为 false 。我的函数是用这样的按钮调用的: <button id="loginbutton" on-tap="connect">Click me!</button>

有人可以帮助我吗?

【问题讨论】:

  • 一件事:O应该大写:readOnly: false
  • 感谢您的提示!

标签: javascript properties polymer polymer-2.x polymer-elements


【解决方案1】:

问题在于属性值的更改。

改为:

connect(){
        this.auth1.value = true;
        console.log("Authenticated" + this.authenticated);

    }

变化可以是这样的:

connect() {
    this.auth1 = true;
    console.log("Authenticated" + this.auth1.value);
}

readonly: false 是默认值,可以删除。

static get properties() {
    return {
        auth1: {
            type: Boolean,
            value: false,
            notify: true
        }
    };
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多