B
B
Bum19892018-09-11 15:59:44
Vue.js
Bum1989, 2018-09-11 15:59:44

How to correctly include a third-party library in a vuejs component for dynamically appearing elements?

I have a table (vuejs component) that has only one row when the page loads. The table also has a button to add a new row.
5b97bbb1c1eb5614892748.png
The last column of the table is input, which uses the dropify library.
The task is to connect dropify to dynamically created inputs in each new line.
Dropify initialization is elementary. You need to get the input element by the selector and apply the dropify() method from the library of the same name with your necessary settings to it.
My solution was to initialize dropify for inputs with the same class in 2 lifecycle hooks - updated and mounted:

updated: function(){
      this.dropifyInit()
    },

mounted: function () {
      this.dropifyInit()
    },


Those. it turns out that for the first line I initialize dropify in the mounted hook, and for all lines added in the future I do this in the updated hook.
I solved the problem, but there is a strong inner conviction that my method is too cumbersome and not very correct.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-09-11
@Bum1989

Make a separate component that will represent your dropify input. In mounted, initialize dropify. And use this component in your table instead of the usual input.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question