1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
| <template>
| <li :class="[prefixCls + '-wrap']" v-show="!hidden">
| <div :class="[prefixCls + '-title']">{{ label }}</div>
| <ul>
| <li :class="[prefixCls]" ref="options"><slot></slot></li>
| </ul>
| </li>
| </template>
| <script>
| const prefixCls = 'ivu-select-group';
|
| export default {
| name: 'OptionGroup',
| props: {
| label: {
| type: String,
| default: ''
| }
| },
| data () {
| return {
| prefixCls: prefixCls,
| hidden: false // for search
| };
| },
| methods: {
| queryChange () {
| this.$nextTick(() => {
| const options = this.$refs.options.querySelectorAll('.ivu-select-item');
| let hasVisibleOption = false;
| for (let i = 0; i < options.length; i++) {
| if (options[i].style.display !== 'none') {
| hasVisibleOption = true;
| break;
| }
| }
| this.hidden = !hasVisibleOption;
| });
| }
| },
| mounted () {
| this.$on('on-query-change', () => {
| this.queryChange();
| return true;
| });
| },
| beforeDestroy() {
| this.$off('on-query-change');
| }
| };
| </script>
|
|