I'm currently developing a chat application using vue.js and firebase. My goal is to retrieve certain data from the database based on the route ID and display it on the screen whenever there is a route change. However, I have encountered unexpected behavior with this data retrieval process.
Here is the section of code:
methods: {
getRoomName() {
db.collection("rooms")
.doc(this.params)
.onSnapshot((snapshot) => (this.roomName = snapshot.data().name));
},
},
watch: {
$route(to, from) {
this.getRoomName();
},
},
The data section looks like this:
data() {
return {
input: "",
roomName: "",
params: this.$route.params.id,
message: "",
roomNameTest: "",
};
},
The template includes this line of code:
<span class="roomName">{{roomName}}</span>