Blame view

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