Firebase和Vuetify应用程序查询:当登录到帐户时,只有该用户可以看到他们添加的帖子,但所有USRE都应该看到它们?我怎么修理
作为我论文的一部分,我创建了一个web应用程序,如下所示: 当我登录到我的主帐户并向页面添加新框时,它们会出现在我的帐户上,但当我创建新的测试帐户时,没有出现?其中一个页面显示最新的框,任何用户都可以看到它们。我希望每个用户都能看到每页上的每个框。有人能帮我吗 下面是显示所有框的页面中的我的代码副本,即使有不同的用户登录:Firebase和Vuetify应用程序查询:当登录到帐户时,只有该用户可以看到他们添加的帖子,但所有USRE都应该看到它们?我怎么修理,firebase,vue.js,google-cloud-firestore,vuetify.js,Firebase,Vue.js,Google Cloud Firestore,Vuetify.js,作为我论文的一部分,我创建了一个web应用程序,如下所示: 当我登录到我的主帐户并向页面添加新框时,它们会出现在我的帐户上,但当我创建新的测试帐户时,没有出现?其中一个页面显示最新的框,任何用户都可以看到它们。我希望每个用户都能看到每页上的每个框。有人能帮我吗 下面是显示所有框的页面中的我的代码副本,即使有不同的用户登录: <template> <div class= "home"> <h1>Lates
<template>
<div class= "home">
<h1>Latest Blockers</h1>
<p v-if="blockers.length == 0">No blockers found</p>
<v-row>
<v-col md="4" v-for="blocker in blockers" :key="blocker.id">
<v-card>
<v-img
v-if="blocker.image"
height="250"
:src="blocker.image"
lazy-src="https://via.placeholder.com/250"
>
</v-img>
<v-card-title>{{ blocker.title }}</v-card-title>
<v-card-text>
<p class="body-1">Date: {{ blocker.date }}</p>
<p class="body-1">Name: {{ blocker.name }}</p>
<p class="body-1">Urgency: {{ blocker.urgency }}</p>
<p>{{ blocker.description }}</p>
</v-card-text>
</v-card>
</v-col>
</v-row>
</div>
</template>
<script>
import { auth, blockersCollection, storage, usersCollection } from '../firebase'
export default {
name: 'Home',
data() {
return {
blockers: []
}
},
methods: {
async getBlockers() {
try {
const querySnapshot = await blockersCollection.get()
querySnapshot.forEach( async (doc) => {
let img = ''
if(doc.data().image) {
img = await storage.ref().child(doc.data().image).getDownloadURL()
}
this.blockers.push({
id: doc.id,
title: doc.data().title,
date: doc.data().date,
name: doc.data().name,
urgency: doc.data().urgency,
description: doc.data().description,
image: img,
img: doc.data().image
})
})
} catch(e) {
console.log(e)
}
}
},
async mounted() {
await this.getBlockers()
}
}
</script>
最新拦截器
未找到阻止程序
{{blocker.title}
日期:{{blocker.Date}
名称:{{blocker.Name}
紧迫性:{{blocker.emergency}
{{blocker.description}}
从“../firebase”导入{auth,BlockerCollection,storage,usersCollection}
导出默认值{
姓名:'家',
数据(){
返回{
阻滞剂:[]
}
},
方法:{
异步getBlockers(){
试一试{
const querySnapshot=wait blockersCollection.get()
querySnapshot.forEach(异步(doc)=>{
设img=''
if(doc.data().image){
img=await storage.ref().child(doc.data().image).getDownloadURL()
}
这个,拦截器,推({
id:doc.id,
标题:doc.data().title,
日期:doc.data().date,
名称:doc.data().name,
紧急情况:doc.data().紧急情况,
description:doc.data().description,
图片:img,
img:doc.data().image
})
})
}捕获(e){
控制台日志(e)
}
}
},
异步装入(){
等待此消息。getBlockers()
}
}
这段代码是我用来添加框的页面:
<template>
<div class="retro">
<h1>Hi, {{ userProfile.name }}, Use the button below to add new retro's:</h1>
<RetroForm />
<v-row>
<v-col md="4" v-for="(retro, index) in retros" :key="retro.id">
<v-card>
<v-img
v-if="retro.image"
height="250"
:src="retro.image"
lazy-src="https://via.placeholder.com/250"
>
</v-img>
<v-card-title>{{ retro.title }}</v-card-title>
<v-card-text>
<p class="subtitle-1">Date: {{ retro.date }}</p>
<p class="subtitle-1">Name: {{ retro.name }}</p>
<p>{{ retro.description }}</p>
</v-card-text>
<v-card-actions>
<RetroForm :retro="retro" :index="index" @retro:updated="updateRetro"/>
<v-btn color="red" @click="deletedConfirm(retro.id, retro.title)" text>Delete</v-btn>
</v-card-actions>
</v-card>
</v-col>
</v-row>
<v-dialog
v-model="deleteDialog"
max-width="400"
>
<v-card>
<v-card-title class="headline">
Delete Retro?
</v-card-title>
<v-card-text>Are you sure you want to delete <b>{{ pTitle }}</b>?</v-card-text>
<v-card-actions>
<v-btn text color="red" @click="deleteRetro">Delete</v-btn>
<v-btn @click="deleteDialog = false" text color="secondary">Close</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</div>
</template>
<script>
import { mapState } from 'vuex'
import RetroForm from '@/components/RetroForm'
import { auth, storage, retrosCollection } from '../firebase'
export default {
components: {
RetroForm
},
data() {
return {
retros: [],
pId: null,
pTitle: null,
deleteDialog: false
}
},
computed: {
...mapState(['userProfile'])
},
methods: {
async updateRetro(doc) {
let img = ''
if(doc.image) {
img = await storage.ref().child(doc.image).getDownloadURL()
}
this.retros.splice(doc.index, 1, {
id: doc.id,
title: doc.title,
date: doc.date,
name: doc.name,
description: doc.description,
image: img,
img: doc.image
})
},
async getRetros() {
try {
const querySnapshot = await retrosCollection.where('userId', '==' , auth.currentUser.uid).get()
querySnapshot.forEach( async (doc) => {
let img = ''
if(doc.data().image) {
img = await storage.ref().child(doc.data().image).getDownloadURL()
}
this.retros.push({
id: doc.id,
title: doc.data().title,
date: doc.data().date,
name: doc.data().name,
description: doc.data().description,
image: img,
img: doc.data().image
})
})
} catch(e) {
console.log(e)
}
},
async deletedConfirm(id, title) {
this.deleteDialog = true
this.pId = id
this.pTitle = title
},
async deleteRetro() {
try {
await retrosCollection.doc(this.pId).delete()
alert('Retro deleted!')
// remove retro from array
this.retros.splice(this.retros.findIndex(x => x.id == this.pId), 1)
this.deleteDialog = false
// reset
this.pId = null
this.pTitle = null
} catch(e) {
console.log(e)
}
}
},
async mounted() {
await this.getRetros()
}
}
</script>
您好,{{userProfile.name},请使用下面的按钮添加新的retro:
{{retro.title}}
日期:{{retro.Date}
名称:{{retro.Name}
{{retro.description}}
删除
删除复古?
确实要删除{{pTitle}吗?
删除
接近
从“vuex”导入{mapState}
从“@/components/RetroForm”导入反转形式
从“../firebase”导入{auth,storage,retrosCollection}
导出默认值{
组成部分:{
反折
},
数据(){
返回{
追溯:[],
pId:null,
pTitle:null,
删除对话框:false
}
},
计算:{
…映射状态(['userProfile'])
},
方法:{
异步updateRetro(文档){
设img=''
如果(文档图像){
img=await storage.ref().child(doc.image).getDownloadURL()
}
此反向拼接(文件索引,1{
id:doc.id,
标题:doc.title,
日期:doc.date,
名称:doc.name,
description:doc.description,
图片:img,
img:doc.image
})
},
异步getRetros(){
试一试{
const querySnapshot=wait retrosCollection.where('userId','=',auth.currentUser.uid).get()
querySnapshot.forEach(异步(doc)=>{
设img=''
if(doc.data().image){
img=await storage.ref().child(doc.data().image).getDownloadURL()
}
这是我的推({
id:doc.id,
标题:doc.data().title,
日期:doc.data().date,
名称:doc.data().name,
description:doc.data().description,
图片:img,
img:doc.data().image
})
})
}捕获(e){
控制台日志(e)
}
},
异步删除配置(id、标题){
this.deleteDialog=true
this.pId=id
this.pTitle=标题
},
异步deleteRetro(){
试一试{
等待retrosCollection.doc(this.pId).delete()
警报('Retro deleted!')
//从阵列中删除追溯
this.retros.splice(this.retros.findIndex(x=>x.id==this.pId),1)
this.deleteDialog=false
//重置
this.pId=null
this.pTitle=null
}捕获(e){
控制台日志(e)
}
}
},
异步装入(){
等待这个
}
}
还有我做的表格
<template>
<div class="retro-form">
<v-btn @click="dialog = !dialog" color="primary" v-if="!retro">Add new retro</v-btn>
<v-btn @click="dialog = !dialog; setData()" color="primary" v-else>Edit retro</v-btn>
<v-dialog v-model="dialog" persistent width="600px">
<v-card>
<v-card-title v-if="!retro">Add new retro</v-card-title>
<v-card-title v-else>Edit retro</v-card-title>
<v-card-text>
<v-form
v-model="valid"
lazy-validation
ref="form"
>
<v-text-field
v-model="title"
:rules="fieldRules"
label="Retro title"
required
outlined
>
</v-text-field>
<v-text-field
v-model="date"
:rules="fieldRules"
label="Retro date"
required
outlined
>
</v-text-field>
<v-text-field
v-model="name"
:rules="fieldRules"
label="Name"
required
outlined
>
</v-text-field>
<v-textarea
v-model="description"
:rules="fieldRules"
label="Retro description"
outlined
required
>
</v-textarea>
<v-file-input
accept="image/*"
label="File input"
v-model="file"
show-size
>
</v-file-input>
<p>Current image:<a v-if="olderImage" :href="olderImage">link</a></p>
<v-btn
elevation="2"
color="primary"
@click="storeRetro"
:loading="isLoading"
v-if="!retro"
>
Store
</v-btn>
<v-btn
elevation="2"
color="primary"
@click="updateRetro"
:loading="isLoading"
v-else
>
Update
</v-btn>
</v-form>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn
color="blue darken-1"
text
@click="dialog = false"
>
Close
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</div>
</template>
<script>
import { retrosCollection, auth, storage } from '../firebase'
export default {
name: 'RetroForm',
props: ['retro', 'index'],
data() {
return {
isLoading: false,
valid: false,
dialog: false,
title: '',
date: '',
name: '',
description: '',
file: null,
fieldRules: [
v => !!v || 'this field is required'
],
olderImage: ''
}
},
methods: {
resetForm() {
this.$refs.form.reset()
},
async storeRetro() {
try {
this.isLoading = false
//upload file
const fileRef = 'events/retros/' + this.file.name
const snapshot = await storage.ref(fileRef).put(this.file)
let data = {
userId: auth.currentUser.uid,
title: this.title,
date: this.date,
name: this.name,
description: this.description,
image: fileRef
}
const doc = await retrosCollection.add(data)
await this.resetForm()
this.isLoading = false
this.dialog = false
} catch(e) {
console.log(e)
}
},
async updateRetro() {
try {
this.isLoading = false
let data = {
userId: auth.currentUser.uid,
title: this.title,
date: this.date,
name: this.name,
description: this.description,
}
if(this.file) {
// delete olderImage
const fileRefOlder = this.retro.img
await storage.ref(fileRefOlder).delete()
//upload file
const fileRef = 'events/retros/' + this.file.name
const snapshot = await storage.ref(fileRef).put(this.file)
data.image = fileRef
} else {
data.image = this.retro.img
}
const doc = await retrosCollection.doc(this.retro.id).update(data)
await this.resetForm()
this.isLoading = false
this.dialog = false
data.index = this.index
this.$emit('retro:updated', data)
alert('Retro updated!')
} catch(e) {
console.log(e)
}
},
setData() {
if(this.retro) {
this.title= this.retro.title
this.date = this.retro.date
this.name = this.retro.name
this.description = this.retro.description
this.olderImage = this.retro.image
}
}
},
mounted() {
this.setData()
}
}
</script>