bootstrap-select插件封装成Vue2.0组件
来源:互联网 发布:湖北旅游 知乎 编辑:程序博客网 时间:2024/06/15 19:59
因为bootstrap-select功能比较强大,而且样式还不错,所以在项目使用了vue所以,觉得对bootstrap-select进行封装。
- 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'); }});
不得不提一下,在使用多个select的时候,在删除某一个selcet对象的时候,加载的值会发生改变,纠结了半天发现是vue自身的问题:因为vue对象有在重新渲染html的过程中会复用原来相同的vue对象,所以导致会导致selcet对象错位。解决方案:将每个select对象打上一个标签key。虽然可能导致性能的下降,但是不会导致错误。
vue官网
0 0
- bootstrap-select插件封装成Vue2.0组件
- 文件上传预览插件 Bootstrap-fileinput组件封装及使用
- VUE2.0+Element-UI+Echarts封装的组件
- Vue2.0+ElementUi封装table组件实现分页功能
- 基于bootstrap的select插件--bootstrap-select
- bootstrap弹窗二次封装成插件
- bootStrap组件与插件
- vue2封装swiper轮播组件
- vue2.0 组件
- vue2.0翻页组件
- VUE2.0组件库
- Vue2.0组件问题
- vue2.0 组件通信
- Vue2.0 组件通信
- Vue2.0 引用插件
- angular2-使用bootstrap-select插件
- 2.vue2.0 jsonp封装
- Vue2.0组件之间通信
- String的不可变性、以及涉及到的字符串常量池和字符串拼接内部实现的剖析
- Java异常处理总结
- day62_mybatis_springMVC_spring整合
- Real Shading in Unreal Engine 4
- python 整型数组
- bootstrap-select插件封装成Vue2.0组件
- Java 基于 TCP/IP 实现 Socket中的多客户端通信
- 2017.4.16一个新的时代
- Leetcode -- 21. Merge Two Sorted Lists
- CAP原理和BASE思想
- 洞见 | 生成对抗网络GAN最近在NLP领域有哪些应用?
- web 配置可访问的静态资源
- C++中获取随机数的方法
- PIC单片机PIC18F26K80中断优先级图