【问题标题】:Firebase function not running/loggingFirebase 功能未运行/记录
【发布时间】:2020-09-21 02:10:47
【问题描述】:

我有一个 firebase 云功能,由于某种原因,即使里面只有 console.log("hello world"),它也没有运行或记录。这让我很困惑,我认为问题可能是由于承诺,但即便如此我认为它应该只使用 console.log()。

我这样调用函数:

const addJobFunction = firestore.functions().httpsCallable("addJob");
addJobFunction({companyName: comp[0].data.Name, jobTitle: this.state.jobTitle,
                    jobLink: this.state.jobLink, companyKey: this.state.company});

函数看起来像:

exports.addJob = functions.https.onCall(async (data, context) => {
  console.log("hello world");
  db.collection("jobs")
    .add({
      company: data.companyName,
      title: data.jobTitle,
      link: data.jobLink,
      data: [],
    });
});

无论数据库添加是否存在(即只是一个console.log),我的日志中的结果是这样的。

【问题讨论】:

    标签: firebase google-cloud-firestore google-cloud-functions


    【解决方案1】:

    原来我在表单提交功能中需要event.preventDefault()

    像这样工作:

    submitJob = (event) => {
        event.preventDefault();
        console.log(this.state.company);
        let comp = this.state.companies.filter((company) => {
          return company.key === this.state.company;
        });
        const addJobFunction = firestore.functions().httpsCallable("addJob");
        addJobFunction({
          companyName: comp[0].data.Name,
          jobTitle: this.state.jobTitle,
          jobLink: this.state.jobLink,
          companyKey: this.state.company,
        });
        this.setState({
            jobTitle: '',
            jobLink: '',
        })
      };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-02
      • 2019-06-25
      • 1970-01-01
      相关资源
      最近更新 更多