Browse Source

Using Vuex action to async/await the mutation and get an up-to-date state.

master
theo1 2 years ago
parent
commit
7f2a4fee07

+ 6
- 3
md-parser/src/components/EditPage.vue View File

@@ -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')
}
}
}

+ 5
- 5
md-parser/src/components/UserInputPage.vue View File

@@ -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>

+ 5
- 1
md-parser/src/store/store.js View File

@@ -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…
Cancel
Save