Answer the question
In order to leave comments, you need to log in
How to create a property in data based on data from firestore?
The component's data has an input_value property that is associated with the input. When loading the page, it was assumed that the value of the input was substituted with the value from the store. But input_value after page load is always = undefined. Tried to force assign in created() and mounted() hooks: this.input_value = this.user.custombutton
<template>
<div>
<span>{{user.custombutton}}</span> <!-- здесь данные в store уже существуют-->
<input v-model="input_value">
</div>
</template>
export default {
name: 'CustomButton',
data: function () {
return {
input_value: this.user.custombutton // а здесь данных в store как будто еще не существует, input_value undefined
}
},
computed: {
user() {
return this.$store.state.user
}
}
}
export default new Vuex.Store({
state: {
user: {}
},
mutations: {
init(state, payload) {
state.user = payload;
}
}
});
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
var userID = user.uid
db.collection("users").doc(userID)
.onSnapshot(function(doc) {
userdata = doc.data()
store.commit('init', userdata)
});
}
new Vue({
el: '#app',
router,
store,
components: { App },
template: '<App/>',
render: h => h(App),
mounted () {
// You'll need this for renderAfterDocumentEvent.
document.dispatchEvent(new Event('render-event'))
}
})
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question