As for data: create property on the basis of data from the firestore?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
29 views
In the data component has a property input_value, which is associated with the input. When the page loads it was assumed that the value of the input, substitute the value from the store. But input_value after page load always = undefined. I tried to force assign hooks created() and mounted(): this.input_value = this.user.custombutton
{{user.custombutton}}  <!-- здесь  данные в store уже существуют-->export default { name: 'CustomButton', data: function () { return { input_value: this.user.custombutton // and here the data in the store as if does not exist, input_value undefined } }, computed: { user() { return this.$store.state.user } } }


index.js (in the directory store/)
export default new Vuex.Store({ state: { user: {} }, mutations: { init(state, payload) { state.user = payload; } } });


main.js (src)
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: '', render: h => h(App) mounted () { // You'll need this for renderAfterDocumentEvent. document.dispatchEvent(new Event('render-event')) } }) });


From the template data store are visible and are rendered during. The feeling that data from the arrive somehow at the wrong time. But after making changes to a file and saving the application is recompiled on the fly in the browser without reloading the page arrives pre-existing data and input is populated with data from store. I was about to make queries to the database directly from the component, but such inputof components I have about 10 pieces, and 10 queries on page load — the solution is not very good, although the working.

What am I doing wrong?

By the way, I'm not the only onewho encountered this.
by | 29 views

1 Answer

0 like 0 dislike
Try to keep track of user changes, ie:
export default { name: 'CustomButton', data() { return { input_value:" } }, computed: { user() { return this.$store.state.user } }, watch: { user(val) { this.input_value = val.custombutton } } }
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked Apr 14, 2019 by AlexBelkevich
0 like 0 dislike
3 answers
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
asked May 20, 2019 by alex_kulkoff
110,608 questions
257,187 answers
0 comments
40,796 users