【发布时间】:2020-08-07 02:12:42
【问题描述】:
我有一个以 Firestore 作为后端的帖子应用...将路由推送到该类别中的参数,以在子集合中显示存储在其中的帖子。
当点击“创建新类别”按钮时,我会找到一种方法立即推送路线,而不必等待将类别添加到列表中......但我不知道该怎么做那是因为类别的id是随机生成的,不知道如何获取,有什么想法吗?
这是我的模板:
<input v-model="newCategory" type="text" placeholder="Category name"/>
<button @click="addCategory">Create new category</button>
<div v-for="(category, index) in categories" :key="index">
<router-link :to="{name: 'Posts', params: {categoryId: category.id}}">
<h3>{{ category.categoryName }}</h3>
</router-link>
</div>
还有脚本:
data() {
return {
newCategory: null,
};
},
methods: {
addCategory() {
this.$firestore.categories.add({
categoryName: this.newCategory
});
this.newCategory = null;
}
},
firestore() {
return {
categories: db.collection("categories")
};
}
【问题讨论】:
标签: javascript html vue.js google-cloud-firestore vue-router