Created
February 5, 2022 15:28
-
-
Save kazuooooo/24c13fd6ca6b7040655186bdab3557a3 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
import { collection, getFirestore, query, where } from "firebase/firestore" | |
import { defineStore } from "pinia" | |
type ExampleDoc = { | |
name: string, | |
age: number | |
} | |
export type State = { | |
queryData: ExampleDoc[] | null, | |
} | |
export const useExampleStore = defineStore('expamle', { | |
state: (): State => { | |
return { | |
queryData: null, | |
} | |
}, | |
actions: { | |
async setup() { | |
// Build query | |
const store = getFirestore() | |
const collectionRef = collection(store, 'Examples') | |
const q = query(collectionRef, where('name', '==', 'wombat')) | |
// Do the magic | |
this.sync('queryData', q) | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment