How to make a form using vuex?

Hi, please explain how to make a form using vuex?

I have this component:

<template><div>
 <input type="text" v-model="template.title" />
 <input type="text" v-model="template.name" />
</div></template>
the <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>


And this repository

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 })
})
},
}


This is not the correct use?

Form fields become reactive and other components begin to pick up the title and name as you type, and I would want that store status changed only after sabmita of the form.

Also don't understand how to be if I want to edit an existing entry and create a new one? In this case fetchTemplate not implemented in computed nothing else, and I get the error Cannot read property 'title' of undefined

Thank you!
March 19th 20 at 09:53
1 answer
March 19th 20 at 09:55
Solution
I wish that store status changed only after sabmita of the form

Then do a local model and will be cleared after you call the mutation with this model.

in computed nothing else, and I get the error Cannot read property 'title' of undefined

See the first paragraph ))
And what about server rendering vue ssr?
Making a local model, I can't save the state of the component. How to save the state components in the ssr vue? - eladio_Barton commented on March 19th 20 at 09:58
@eladio_Barton, server rendering You only need to get initialized data. - Bud_Haag95 commented on March 19th 20 at 10:01

Find more questions by tags Vue.js