溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

bootstrap中select插件怎么封裝成Vue2.0組件

發(fā)布時(shí)間:2022-04-27 10:56:32 來(lái)源:億速云 閱讀:195 作者:iii 欄目:大數(shù)據(jù)

本文小編為大家詳細(xì)介紹“bootstrap中select插件怎么封裝成Vue2.0組件”,內(nèi)容詳細(xì),步驟清晰,細(xì)節(jié)處理妥當(dāng),希望這篇“bootstrap中select插件怎么封裝成Vue2.0組件”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來(lái)學(xué)習(xí)新知識(shí)吧。

html

<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='請(qǐng)選擇' 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');
 }
});

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

bootstrap中select插件怎么封裝成Vue2.0組件

讀到這里,這篇“bootstrap中select插件怎么封裝成Vue2.0組件”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識(shí)點(diǎn)還需要大家自己動(dòng)手實(shí)踐使用過(guò)才能領(lǐng)會(huì),如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI