J
J
jazzus2018-12-28 15:11:30
Vue.js
jazzus, 2018-12-28 15:11:30

How to make a single edit/create VUE form?

I'm interested in the technology of working with one form (separate editing/creation pages work for me). How do you do it? For example, the form for adding/editing an article. Maybe someone has an example? It is desirable to be as simple as possible and not complicated by routes or something else. I work in default Vue + Laravel. I start to write a bicycle and run into errors. You need to pass the props of the article object to the form (for editing). And it works. But when creating this props is missing. And it doesn't work. Of course, you can create an object with empty values ​​​​when creating an article, pass this empty object .. But I feel that I'm thinking in the wrong direction) And you need to learn about best practices in general. I don't want to fetch the object either. need a reactive relationship with the parent after saving and updating the object. I would be grateful for information or an example. Preferably without VUE routes. at this stage I do not want to climb into the jungle and understand simple things.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2018-12-28
@jazzus

In general, I wrote a bicycle and it works. I'll post the solution for now. What I did:
1) When creating an article, I pass an empty article object to the props. I prepare an empty object in advance. Something like article={'name: ''}. I transfer from the parent to the form
2) when editing. In the same form, I pass the props of the filled article object. This is clear.
3) In the form itself, the field was edit=true/false. If number of characters in (article.name)==0 then edit==true. And since we get edit, a wide scope of actions opens up:
You can change buttons, names in the form. For example: create/edit
Different save and edit methods can be called
Which is what I did. Now I'll try in the Laravel controller in one method to create and edit, and it will be fine.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question