Last active
January 19, 2019 05:46
-
-
Save miminari/a2aca5dbe9cc593188c2a34abbcd6ea4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<section class="container"> | |
<div> | |
<h1 class="title">test app</h1> | |
<div v-if="projects.length != 0"> | |
<ul> | |
<li v-for="project in projects" :key="project.id"> | |
<nuxt-link :to="'/projects/'+project.projectID">{{ project.name }}</nuxt-link> | |
</li> | |
</ul> | |
</div> | |
</div> | |
</section> | |
</template> | |
<script> | |
import db from "~/plugins/firebase"; | |
export default { | |
async asyncData({ params }) { | |
return { | |
projects: await getAllDocs("projects") | |
}; | |
} | |
}; | |
// get all documents | |
async function getAllDocs(collection) { | |
let obj = []; | |
let colRef = db.collection(collection); | |
const allSnapShot = await colRef.get(); | |
allSnapShot.forEach(doc => { | |
obj.push(doc.data()); | |
}); | |
return obj; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment