Answer the question
In order to leave comments, you need to log in
How to make a form using vuex?
Hello, can you please explain how to properly make a form using vuex?
I have a component like this:
<template><div>
<input type="text" v-model="template.title" />
<input type="text" v-model="template.name" />
</div></template>
<script>
export default {
computed: {
template() {
return this.$store.state.templates[this.$route.params.id]
},
},
mounted() {
if(this.$route.params.id) {
return this.$store.dispatch('fetchTemplate', this.$route.params.id)
}
}
}
</script>
mutations: {
setTemplate(state, { id, template }) {
Vue.set(state, id, template)
},
},
actions: {
async fetchTemplate({commit}, id) {
return await axios.get('http://127.0.0.1:8000/api/templates/' + id).then(result => {
const template = result.data
commit('setTemplate', { id, template })
})
},
}
Answer the question
In order to leave comments, you need to log in
I want the state of the repository to change only after submitting the form
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question