Параметр Select2 First в массиве всегда показывает первый, а не заполнитель - PullRequest
0 голосов
/ 24 сентября 2019

Вот код для select2 компонента

Vue.component('select2', {
  props: ['options', 'value'],
  template: '<select style="width: 100%" v-on:change="$emit(\'change\', $event.target.value)"><slot></slot></select>',
  mounted: function() {
    var vmselect = this
    $(this.$el)
      // init select2
      .select2({
        data: this.options
      })
      .val(this.value)
      .trigger('change')
      // emit event on change.
      .on('change', function() {
        vmselect.$emit('input', this.value)
      })
  },
  watch: {
    value: function(value) {
      // update value
      $(this.$el)
        .val(value)
        .trigger('change')
    },
    options: function(options) {
      // update options
      $(this.$el).empty().select2({
        placeholder: {
          id: '-1', // the value of the option
          text: 'Select an option'
        },
        allowClear: true,
        data: options
      })
    }
  },
  destroyed: function() {
    $(this.$el).off().select2('destroy')
  }
})

И это HTML-код

<div class="form-group">
   <label class="">Kota Tempat Tinggal</label>
   <select2 name="domisili" :options="list.areas" v-model="form.domicilecity"></select2>
</div>

API массива работает отлично, но единственная проблема заключается в том, что первое значениев массиве, всегда показывающем вместо заполнителя, как мне сделать так, чтобы заполнитель отображался первым?

...