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_created": data.date_created,
|
||||||
"date_modified": data.date_modified,
|
"date_modified": data.date_modified,
|
||||||
})
|
})
|
||||||
// update content
|
// Call the Vuex action to update the content,
|
||||||
this.$store.commit('updateText', data.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 => {
|
response => {
|
||||||
console.log('Error: ', response)
|
console.log('Error: ', response)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
this.$router.push('/write')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,21 +25,21 @@ export default {
|
|||||||
},
|
},
|
||||||
data: function() {
|
data: function() {
|
||||||
return{
|
return{
|
||||||
userText: '',
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// saves article content
|
// saves article content
|
||||||
articleUpate : function() {
|
articleUpate : function() {
|
||||||
console.log('updating in UserInputPage')
|
|
||||||
this.userText = this.$store.getters.getContent
|
this.userText = this.$store.getters.getContent
|
||||||
},
|
},
|
||||||
articlePublish: function(){
|
articlePublish: function(){
|
||||||
this.$router.push('/published')
|
this.$router.push('/published')
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
mounted: function(){
|
computed: {
|
||||||
this.userText = this.$store.getters.getContent
|
userText: function(){
|
||||||
|
return this.$store.getters.getContent
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -30,7 +30,6 @@ export const store = new Vuex.Store({
|
|||||||
today (state, date) {
|
today (state, date) {
|
||||||
let dateObj = new Date()
|
let dateObj = new Date()
|
||||||
let today = dateObj.getDate() + '/' + dateObj.getMonth() + '/' + dateObj.getFullYear()
|
let today = dateObj.getDate() + '/' + dateObj.getMonth() + '/' + dateObj.getFullYear()
|
||||||
console.log("Today : ", today)
|
|
||||||
if (date === 1) {
|
if (date === 1) {
|
||||||
state.article.meta.date_created = today
|
state.article.meta.date_created = today
|
||||||
}
|
}
|
||||||
@ -42,5 +41,10 @@ export const store = new Vuex.Store({
|
|||||||
state.article.meta = {}
|
state.article.meta = {}
|
||||||
state.article.content = ""
|
state.article.content = ""
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
updateText(context, newText){
|
||||||
|
context.commit('updateText', newText)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user