我是 Vue 和 Vuefire 的新手。我正在尝试使用 key 作为 URL ID 创建指向页面的动态链接。
我的引用设置为
let db = app.database();
const postsRef = db.ref('posts');
然后我像这样将全局引用导入我的应用程序页面 -
firebase: {
posts: {
source: postsRef,
asObject: true,
readyCallback: function () {
console.log(postsRef)
}
},
},
并像这样遍历 posts 对象 -
<div v-for="post in posts">
<a :href="'post/' + post.key"></a>
</div>
我的数据库结构如下 - DB Structure
考虑到我可能想在帖子页面检索,最好不使用 URL 参数,使用 key 的最佳方式是什么?当我记录 postsRef 对象时,我看到父值为 null,键值为 posts。我希望键值在 for 循环中检索元素的唯一 ID。
最佳答案
所以基本上,删除 asObject: true 并将其作为数组导入对我来说是可行的。在我的例子中, key 可以访问为
post['.key']
关于javascript - Vuefire - 在 v-for 循环中获取 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46933354/