How do I reuse Vue components?

  • 0
    For example, we have a table component, in the header of which there is a button for adding an element. There are several tables in the application, each, when adding a new element through a button, must add this element through different api methods to different database tables. Can this be done and how?
    JavaScript Anonymous, May 19, 2020

  • 2 Answers
  • 0
    The component emits the event, the parent subscribes to it by assigning its own handler. Thus, in each specific case, the handlers can be different and the same component becomes universal. See example:

    Anonymous

  • 0
    Pass to the component as props a function that should be called when the button is pressed / the line is edited.

    Instead of directly writing to the component, you can raise an event, and handle it at the place where the component is inserted.
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!