Skip to content Skip to sidebar Skip to footer

Rendering A Component Directive In Vue 2 Without Params

I have an app that holds the student list data. The component is supposed to take in that list and render a select dropdown (with select2). In the fiddles console, it's displaying

Solution 1:

First, as I mentioned in comments, I would suggest you do this with a component. If you had to stick with a directive, however, you can't initialize select2 in the bind hook. You've defined your options in the DOM, so you need to wait until the component is inserted to initialize it.

directives: {
    select: {
        inserted: function(el, binding, vnode) {
            var select = $(el);
            select.select2();
            select.on('change', function() {
                console.log('hey on select works!');
             });
        },
    },
},

Here is an update of your fiddle.

Post a Comment for "Rendering A Component Directive In Vue 2 Without Params"