【问题标题】:Accessing elements in Polymer 3.0在 Polymer 3.0 中访问元素
【发布时间】:2019-07-15 14:51:07
【问题描述】:

无法调用函数。无法通过 this.$.id 访问元素。我可以在 Polymer 2.0 中完成所有这些工作,但我正在尝试升级到 Polymer 3.0。

ready() {
    super.ready();

    this.$.login.addEventListener('login', this.login);
    this.$.login.addEventListener('forgot-password', this.forgotPassword);
}

login(e) {
    const username = e.detail.username;
    const password = e.detail.password;

    auth.signInWithEmailAndPassword(username, password)
        .then(user => {
            // why doesn't this work
            this.getUserFromFirestore(user.uid);
        })
        .catch(error => {
            console.log(error);
            // why doesn't this work
            this.$.login.error = true;
        });
}

getUserFromFirestore(uid) {
    firestore.collection('users').doc(uid)
        .get()
        .then(doc => {
            let user = doc.data();
            console.log(user.role);
        })
        .catch(error => {
            console.log(error);
        });
}

使用 Firebase 身份验证。这行得通,但是当我调用 getUserFromFirestore 函数时,我收到“TypeError:this.getUserFromFirestore is not a function”

【问题讨论】:

    标签: polymer polymer-starter-kit polymer-3.x


    【解决方案1】:

    我只是猜测......

    你试过了吗

    constructor () {
        this.login = this.login.bind(this);
    }
    

    ?

    【讨论】:

    • 另一种方法是this.$.login.addEventListener('login', (e) => this.login(e));
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多