iview/src/components/select/option-group.vue

49 lines
1.4 KiB
Vue
Raw Normal View History

<template>
2017-01-13 16:46:20 +08:00
<li :class="[prefixCls + '-wrap']" v-show="!hidden">
2016-10-28 17:24:52 +08:00
<div :class="[prefixCls + '-title']">{{ label }}</div>
<ul>
2017-03-06 18:24:57 +08:00
<li :class="[prefixCls]" ref="options"><slot></slot></li>
</ul>
</li>
</template>
<script>
const prefixCls = 'ivu-select-group';
export default {
2017-03-06 18:24:57 +08:00
name: 'OptionGroup',
props: {
label: {
type: String,
default: ''
}
},
data () {
return {
2017-01-13 16:46:20 +08:00
prefixCls: prefixCls,
hidden: false // for search
2016-12-25 22:49:42 +08:00
};
2017-01-13 16:46:20 +08:00
},
methods: {
queryChange () {
this.$nextTick(() => {
2017-03-06 18:24:57 +08:00
const options = this.$refs.options.querySelectorAll('.ivu-select-item');
2017-01-13 16:46:20 +08:00
let hasVisibleOption = false;
for (let i = 0; i < options.length; i++) {
if (options[i].style.display !== 'none') {
hasVisibleOption = true;
break;
}
}
this.hidden = !hasVisibleOption;
});
}
},
2017-03-06 18:24:57 +08:00
mounted () {
this.$on('on-query-change', () => {
2017-01-13 16:46:20 +08:00
this.queryChange();
return true;
2017-03-06 18:24:57 +08:00
});
}
2016-12-25 22:49:42 +08:00
};
2016-10-28 17:24:52 +08:00
</script>