Blame view

src/components/menu/menu-item.vue 2.07 KB
8778b343   梁灏   init Menu components
1
  <template>
4bce7645   zhigang.li   make menu support...
2
      <li :class="classes" @click.stop="handleClick" :style="itemStyle"><slot></slot></li>
8778b343   梁灏   init Menu components
3
4
  </template>
  <script>
fd1582c5   梁灏   support Menu & La...
5
      import Emitter from '../../mixins/emitter';
acba45fe   zhigang.li   move computed val...
6
      import { findComponentUpward } from '../../utils/assist';
e05d7289   梁灏   update Menu
7
      const prefixCls = 'ivu-menu';
acba45fe   zhigang.li   move computed val...
8
      import mixin from './mixin';
e05d7289   梁灏   update Menu
9
  
8778b343   梁灏   init Menu components
10
      export default {
e05d7289   梁灏   update Menu
11
          name: 'MenuItem',
acba45fe   zhigang.li   move computed val...
12
          mixins: [ Emitter, mixin ],
e05d7289   梁灏   update Menu
13
          props: {
fd1582c5   梁灏   support Menu & La...
14
              name: {
e05d7289   梁灏   update Menu
15
16
17
18
19
20
21
22
                  type: [String, Number],
                  required: true
              },
              disabled: {
                  type: Boolean,
                  default: false
              }
          },
8778b343   梁灏   init Menu components
23
          data () {
e05d7289   梁灏   update Menu
24
25
              return {
                  active: false
b0893113   jingsam   :art: add eslint
26
              };
e05d7289   梁灏   update Menu
27
28
29
30
31
32
33
34
35
36
          },
          computed: {
              classes () {
                  return [
                      `${prefixCls}-item`,
                      {
                          [`${prefixCls}-item-active`]: this.active,
                          [`${prefixCls}-item-selected`]: this.active,
                          [`${prefixCls}-item-disabled`]: this.disabled
                      }
b0893113   jingsam   :art: add eslint
37
                  ];
4bce7645   zhigang.li   make menu support...
38
              },
4bce7645   zhigang.li   make menu support...
39
              itemStyle () {
b2d676bd   zhigang.li   fixed the bug abo...
40
                  return this.hasParentSubmenu && this.mode !== 'horizontal' ? {
4bce7645   zhigang.li   make menu support...
41
42
                      paddingLeft: 43 + (this.parentSubmenuNum - 1) * 24 + 'px'
                  } : {};
e05d7289   梁灏   update Menu
43
              }
8778b343   梁灏   init Menu components
44
          },
e05d7289   梁灏   update Menu
45
46
          methods: {
              handleClick () {
0acdae19   梁灏   update Menu
47
                  if (this.disabled) return;
fd1582c5   梁灏   support Menu & La...
48
  
4bce7645   zhigang.li   make menu support...
49
                  let parent = findComponentUpward(this, 'Submenu');
fd1582c5   梁灏   support Menu & La...
50
51
52
53
54
55
  
                  if (parent) {
                      this.dispatch('Submenu', 'on-menu-item-select', this.name);
                  } else {
                      this.dispatch('Menu', 'on-menu-item-select', this.name);
                  }
e05d7289   梁灏   update Menu
56
              }
fd1582c5   梁灏   support Menu & La...
57
58
59
60
61
          },
          mounted () {
              this.$on('on-update-active-name', (name) => {
                  if (this.name === name) {
                      this.active = true;
4bce7645   zhigang.li   make menu support...
62
                      this.dispatch('Submenu', 'on-update-active-name', name);
fd1582c5   梁灏   support Menu & La...
63
64
65
66
                  } else {
                      this.active = false;
                  }
              });
e05d7289   梁灏   update Menu
67
          }
b0893113   jingsam   :art: add eslint
68
69
      };
  </script>