Currently I have separate components CreateUser.vue and EditUser.vue with very big form.
- Route for
CreateUseris/users - Route for
EditUseris/users/:username.
The backend API is also different:
- POST for create (
example.com/users) and - PUT for edit (
example.com//users/:username).
Also in EditUser, username field is readonly as it cannot be edited once created otherwise both CreateUser and EditUser templates are same but Javascript part is different.
Question:
How can I combine this into one Component UserForm.vue and eliminate CreateUser.vue and EditUser.vue ?
In the main UI there is a button Create User which routes to CreateUser component. In the list of users view, each row has a button Edit which routes to EditUser component.
I am using Vue router for defining routes similar to below:
{
path: '/users',
name: 'createUser',
component: CreateUser
},
{
path: '/users/:id',
component: EditUser,
name: 'editUser'
}