从Fireabse读取数据

时间:2020-04-18 14:36:43

标签: javascript firebase google-cloud-firestore

如何从数据库中读取电子邮件并登录并显示在控制台中?

function setupBase() {
    var firebaseConfig = {
      ...
    };

    firebase.initializeApp(firebaseConfig);

    var firestore = firebase.firestore();

    const form = document.querySelector('form');

    const db = firestore.collection('User');

    form.addEventListener('submit', function (e) {
        e.preventDefault();
        let userEmail = document.querySelector('.input-email').value;
        let userPassword = document.querySelector('.input-password').value;

        db.doc().set({
            email: userEmail,
            password: userPassword
        }).then(function () {
            console.log('Data Saved')
            document.querySelector('.input-email').value = ''
            document.querySelector('.input-password').value = ''
            document.querySelector('.icon-done>i').classList.toggle('active');

        }).catch(function () {
            console.log('Error')
        })

    })


}

export default setupBase;

0 个答案:

没有答案