Using Vuex action to async/await the mutation and get an up-to-date state.
This commit is contained in:
parent
5b94913feb
commit
7f2a4fee07
@ -56,14 +56,17 @@ export default {
|
||||
"date_created": data.date_created,
|
||||
"date_modified": data.date_modified,
|
||||
})
|
||||
// update content
|
||||
this.$store.commit('updateText', data.content)
|
||||
// Call the Vuex action to update the content,
|
||||
// and await the mutation to be over before going to the Input page.
|
||||
this.$store.dispatch('updateText', data.content)
|
||||
.then(() => {
|
||||
this.$router.push('/write')
|
||||
})
|
||||
},
|
||||
response => {
|
||||
console.log('Error: ', response)
|
||||
}
|
||||
)
|
||||
this.$router.push('/write')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,21 +25,21 @@ export default {
|
||||
},
|
||||
data: function() {
|
||||
return{
|
||||
userText: '',
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// saves article content
|
||||
articleUpate : function() {
|
||||
console.log('updating in UserInputPage')
|
||||
this.userText = this.$store.getters.getContent
|
||||
},
|
||||
articlePublish: function(){
|
||||
this.$router.push('/published')
|
||||
}
|
||||
},
|
||||
},
|
||||
mounted: function(){
|
||||
this.userText = this.$store.getters.getContent
|
||||
computed: {
|
||||
userText: function(){
|
||||
return this.$store.getters.getContent
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -30,7 +30,6 @@ export const store = new Vuex.Store({
|
||||
today (state, date) {
|
||||
let dateObj = new Date()
|
||||
let today = dateObj.getDate() + '/' + dateObj.getMonth() + '/' + dateObj.getFullYear()
|
||||
console.log("Today : ", today)
|
||||
if (date === 1) {
|
||||
state.article.meta.date_created = today
|
||||
}
|
||||
@ -42,5 +41,10 @@ export const store = new Vuex.Store({
|
||||
state.article.meta = {}
|
||||
state.article.content = ""
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
updateText(context, newText){
|
||||
context.commit('updateText', newText)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user