Blame view

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