我的firestore功能没有响应我的VUE组件挂钩功能“ beforerouteenter”。
这就是我的firestore文件中的内容
import { db } from "./firebase"
import { collection, doc,onSnapshot,query} from "firebase/firestore"
import { ref, onUnmounted} from "vue"
export const uesQueryProject = async()=>{
const events =ref([])
const q = query(
collection(db , "events")
)
const unsub = onSnapshot(q,(snapshot)=>{
events.value=snapshot.docs.map(
doc=>({
id:doc.id,
...doc.data()
})
)
})
onUnmounted(unsub)
return events
}
这是我的VUE组件试图从生命周期钩中调用的内容
beforeRouteEnter(routeTo, routeFrom, next) {
uesQueryProject()
.then(response => {
next(comp => {
console.log(response.data)
if(response.data){
console.log('yas')
comp.events = response.data
}
})
})
.catch(() => {
next({ name: 'NetworkError' })
})
,
所以(响应.data)是空的,我不知道为什么,我尝试在“ use querquyproject”函数的侧面安装log(doc),并且在vue组件函数的一边没有响应
this is what's in my firestore file
import { db } from "./firebase"
import { collection, doc,onSnapshot,query} from "firebase/firestore"
import { ref, onUnmounted} from "vue"
export const uesQueryProject = async()=>{
const events =ref([])
const q = query(
collection(db , "events")
)
const unsub = onSnapshot(q,(snapshot)=>{
events.value=snapshot.docs.map(
doc=>({
id:doc.id,
...doc.data()
})
)
})
onUnmounted(unsub)
return events
}
This is what my vue components try to call from the life cycle hook
beforeRouteEnter(routeTo, routeFrom, next) {
uesQueryProject()
.then(response => {
next(comp => {
console.log(response.data)
if(response.data){
console.log('yas')
comp.events = response.data
}
})
})
.catch(() => {
next({ name: 'NetworkError' })
})
},
so the (response.data) is empty i don't know why,i try to consol log (doc) in side the "useQueryProject" function and it works but in side the vue component function there is no responde
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论