因为bootstrap-select功能比较强大,而且样式还不错,所以在项目使用了vue,所以,觉得对bootstrap-select进行封装。
html
代码如下:
js
rush:js;">
// select 插件
Vue.component('vm-select',{
props : ['options','value','multiple','method','load','index','childidx'],template : "",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。虽然可能导致性能的下降,但是不会导致错误。
nofollow" target="_blank" href="https://cn.vuejs.org/v2/guide/list.html">vue官网
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。
原文地址:https://www.jb51.cc/vue/39930.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。