[Vuejs]-Select2 and Vue Directive

2๐Ÿ‘

โœ…

I had a similar issue with select2, and had to use paramwatchers to check when options was updated:

select: {
    twoWay: true,
    priority: 1000,

    params: ['options'],

    paramswatchers: {
         "options": function (val, oldVal) {
             $(this.el).select2({
                 data: val
             })
         }
    }

    bind: function () {
        var self = this;

        $(this.el).select2({
            theme: "bootstrap",
            closeOnSelect: true,
            minimumInputLength: 3,
            data: this.params.options
        })
        .on('change', function () {
            self.set(this.value)
        })
    },
    update: function (value) {
        $(this.el).val(value).trigger('change')
    },
    unbind: function () {
        $(this.el).off().select2('destroy')
    }
}

Source: https://vuejs.org/guide/custom-directive.html#params

๐Ÿ‘คNegorath

Leave a comment