【问题标题】:Bootstrap Select not working inside Bootstrap Vue ModalBootstrap Select 在 Bootstrap Vue 模式中不起作用
【发布时间】:2019-07-03 09:45:08
【问题描述】:

我正在使用带有 Bootstrap 选择的 Bootstrap Vue,并且选择在模态之外完美地工作 它在模式内根本没有打开。直播代码是HERE

JS 文件

Vue.component("suluct", {
  template: "#suluct",
  props: {
    week: [String, Number],
    year: [String, Number],
  },

  mounted() {
    const $selectpicker = $(this.$el).find('.selectpicker');

    $selectpicker
      .selectpicker()
      .on('changed.bs.select', () => this.$emit('changeWeek', this.options[$selectpicker.val()]));
  },

  updated() {
    $(this.$el).find('.selectpicker').selectpicker('refresh');
  },

  destroyed() {
    $(this.$el).find('.selectpicker')
      .off()
      .selectpicker('destroy');
  },

  computed: {
    options() {
        // run some logic here to populate options
      return [
        {
        title: "Sunday",
        value: "sunday",
      }, {
        title: "Monday",
        value: "monday"
      }
      ]
    }
  }
})

new Vue({
  el: "#app"
})

HTML

<div id="app">
  <suluct></suluct>

  <div>
    <b-btn v-b-modal.modal1>Launch demo modal</b-btn>

    <!-- Modal Component -->
    <b-modal id="modal1" title="Bootstrap-Vue">
      <suluct></suluct>
    </b-modal>
  </div>
</div>


<script type="text/x-template" id="suluct">
  <select class="form-control selectpicker bs-select">
    <option
      v-for="(option, index) in options"
      :key="index"
      :value="option.value"
      :selected="option.selected">
      {{ option.title }}
    </option>
  </select>
</script>

下拉选择根本不会打开。任何帮助表示赞赏

【问题讨论】:

    标签: vue.js bootstrap-modal vue-component bootstrap-select bootstrap-selectpicker


    【解决方案1】:

    我遇到了同样的问题。尝试了各种方法,终于找到了解决办法。

    当你想显示模态框时,不要使用 v-b-modal 指令。

    创建一个方法,使用 this.$bvModal.show() 来显示模态。

    然后你应该使用 this.$nextTick([callback])

    最后,在回调方法中使用javascript调用bootstrap-select 该方法将像

    HTML

    <b-btn @click="ShowModal">Launch demo modal</b-btn>
    

    Js

    ...
    ShowModal() {
        this.$bvModal.show('modal1');
        this.$nextTick(()=>{
            $('select').selectpicker();
        })
    },
    ...
    

    ps:对不起,我的英语很差,希望你能明白我的意思

    【讨论】:

      猜你喜欢
      • 2019-06-24
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 2014-06-15
      • 2018-08-06
      • 2018-04-07
      • 1970-01-01
      • 2014-09-16
      相关资源
      最近更新 更多