欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

bootstrap select插件封裝成Vue2.0組件

 更新時間:2017年04月17日 10:12:07   作者:vivid_renzaijianghu  
這篇文章主要為大家詳細(xì)介紹了bootstrap select插件封裝成Vue2.0組件的相關(guān)方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下

因?yàn)閎ootstrap-select功能比較強(qiáng)大,而且樣式還不錯,所以在項(xiàng)目使用了vue,所以,覺得對bootstrap-select進(jìn)行封裝。

html

復(fù)制代碼 代碼如下:
<my-select :options="input.options" v-model="input.value" ref="typeSelect" :index="index" :childidx="childIdx" :load="load" :multiple="input.multiple" :method="change"></my-select>

js

// select 插件
Vue.component('vm-select', {
 props : ['options', 'value', 'multiple', 'method', 'load', 'index', 'childidx'],
 template : "<select :multiple='multiple' class='selectpicker' data-live-search='true' title='請選擇' data-live-search-placeholder='搜索'><option :value='option.value' v-for='option in options'>{{ option.label }}</option></select>",
 mounted : function () {
 var vm = this;
 $(this.$el).selectpicker('val', this.value != null ? this.value : null);
 $(this.$el).on('changed.bs.select', function () {
 vm.$emit('input', $(this).val());
 if (typeof(vm.method) != 'undefined') {
 vm.method(vm.index, vm.childidx, this.value);
 }
 });
 $(this.$el).on('show.bs.select', function () {
 if (typeof(vm.load) != 'undefined') {
 vm.load(vm.index, vm.childidx);
 }
 });
 },
 updated : function () {
 $(this.$el).selectpicker('refresh');
 },
 destroyed : function () {
 $(this.$el).selectpicker('destroy');
 }
});

不得不提一下,在使用多個select的時候,在刪除某一個selcet對象的時候,加載的值會發(fā)生改變,糾結(jié)了半天發(fā)現(xiàn)是vue自身的問題:因?yàn)関ue對象有在重新渲染html的過程中會復(fù)用原來相同的vue對象,所以導(dǎo)致會導(dǎo)致selcet對象錯位。解決方案:將每個select對象打上一個標(biāo)簽key。雖然可能導(dǎo)致性能的下降,但是不會導(dǎo)致錯誤。

這里寫圖片描述

vue官網(wǎng)

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論