firebase에서 CRUD
2022. 12. 30. 15:33ㆍ카테고리 없음
#1 파이어베이스에서 데이터 호출
getDataList(){
const self = this;
const db = firebase.firestore();
db.collection(self.fbCollection)
.get()
.then((querySnapshot) => {
if (querySnapshot.size === 0) {
return
}
querySnapshot.forEach((doc) => {
const _data = doc.data();
// const _user = doc.data().doc(self._data.id);
_data.id = doc.id
console.log(_data)
self.rows.push(_data);
});
})
},
#2 특정 ID의 데이터 호출
getData(){
const self = this;
const db = firebase.firestore();
db.collection(self.fbCollection)
.doc(this.docId)
.get()
.then((snapshot) => {
const _data = snapshot.data();
this.rows = _data
})
},
#3 특정 ID의 모든 데이터 삭제
deleteUser() {
const self = this;
const db = firebase.firestore();
db.collection(self.fbCollection)
.doc(this.docId)
.delete()
.then(() => {
self.$router.push('/')
})
},
#4 특정 ID의 데이터 수정
modifyData() {
const self = this;
const db = firebase.firestore();
db.collection(self.fbCollection)
.doc(this.docId)
.update({
name: self.row.modifyName,
age: self.row.modifyAge,
gender: self.row.modifyGender,
school: self.row.modifySchool,
schoolNum: self.row.modifySchoolNum,
phoneNum: self.row.modifyPhoneNum,
})
.then(() => {
self.$router.push('/')
})
},