首页 > 解决方案 > 增量值在使用示例代码的 Firestore 中不起作用

问题描述

在 Firestore 文档的此页面上,提供的代码在我的 Vue 项目中不起作用。

https://cloud.google.com/firestore/docs/manage-data/add-data#increment_a_numeric_value

Firestore 在我的 Vue 应用程序中被广泛使用。它甚至被用在我正在尝试的同一页面上。

我正在使用 VUE CLI 3、firebase 6.0.2、firebase-admin 8.0.0、vue 2.6.10。

var washingtonRef = db.collection('cities').doc('DC');

// Atomically increment the population of the city by 50.
washingtonRef.update({
    population: firebase.firestore.FieldValue.increment(50)
});

控制台中的错误消息显示“firebase”未定义。如果我取出“firebase”,它会说“firestore”没有定义。如果我取出“firestore”,它会显示“未定义 FieldValue”。

为什么它不起作用?我只想添加简单的投票。

标签: vuejs2google-cloud-firestore

解决方案


推荐阅读