這篇文章主要介紹bootstrap中select插件如何封裝成Vue2.0組件,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
因?yàn)閎ootstrap-select功能比較強(qiáng)大,而且樣式還不錯(cuò),所以在項(xiàng)目使用了vue,所以,覺得對bootstrap-select進(jìn)行封裝。
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='請選擇' 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對象的時(shí)候,加載的值會發(fā)生改變,糾結(jié)了半天發(fā)現(xiàn)是vue自身的問題:因?yàn)関ue對象有在重新渲染html的過程中會復(fù)用原來相同的vue對象,所以導(dǎo)致會導(dǎo)致selcet對象錯(cuò)位。解決方案:將每個(gè)select對象打上一個(gè)標(biāo)簽key。雖然可能導(dǎo)致性能的下降,但是不會導(dǎo)致錯(cuò)誤。
以上是“bootstrap中select插件如何封裝成Vue2.0組件”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司行業(yè)資訊頻道!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站chinadenli.net,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
本文題目:bootstrap中select插件如何封裝成Vue2.0組件-創(chuàng)新互聯(lián)
文章地址:http://chinadenli.net/article46/dojhhg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、品牌網(wǎng)站建設(shè)、服務(wù)器托管、商城網(wǎng)站、定制網(wǎng)站、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容