Blame view

src/components/menu/menu-item.vue 2.72 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';
7d0b7384   梁灏   fixed #3484
7
      import { findComponentUpward, oneOf } 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
24
25
26
27
28
29
30
31
32
33
34
35
36
              },
              to: {
                  type: [Object, String]
              },
              replace: {
                  type: Boolean,
                  default: false
              },
              target: {
                  type: String,
                  validator (value) {
                      return oneOf(value, ['_blank', '_self', '_parent', '_top']);
                  },
                  default: '_self'
e05d7289   梁灏   update Menu
37
38
              }
          },
8778b343   梁灏   init Menu components
39
          data () {
e05d7289   梁灏   update Menu
40
41
              return {
                  active: false
b0893113   jingsam   :art: add eslint
42
              };
e05d7289   梁灏   update Menu
43
44
45
46
47
48
49
50
51
52
          },
          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
53
                  ];
4bce7645   zhigang.li   make menu support...
54
              },
4bce7645   zhigang.li   make menu support...
55
              itemStyle () {
b2d676bd   zhigang.li   fixed the bug abo...
56
                  return this.hasParentSubmenu && this.mode !== 'horizontal' ? {
4bce7645   zhigang.li   make menu support...
57
58
                      paddingLeft: 43 + (this.parentSubmenuNum - 1) * 24 + 'px'
                  } : {};
e05d7289   梁灏   update Menu
59
              }
8778b343   梁灏   init Menu components
60
          },
e05d7289   梁灏   update Menu
61
          methods: {
7d0b7384   梁灏   fixed #3484
62
              handleClickItem (event) {
0acdae19   梁灏   update Menu
63
                  if (this.disabled) return;
fd1582c5   梁灏   support Menu & La...
64
  
4bce7645   zhigang.li   make menu support...
65
                  let parent = findComponentUpward(this, 'Submenu');
fd1582c5   梁灏   support Menu & La...
66
67
68
69
70
71
  
                  if (parent) {
                      this.dispatch('Submenu', 'on-menu-item-select', this.name);
                  } else {
                      this.dispatch('Menu', 'on-menu-item-select', this.name);
                  }
7d0b7384   梁灏   fixed #3484
72
73
  
                  this.handleCheckClick(event);
e05d7289   梁灏   update Menu
74
              }
fd1582c5   梁灏   support Menu & La...
75
76
77
78
79
          },
          mounted () {
              this.$on('on-update-active-name', (name) => {
                  if (this.name === name) {
                      this.active = true;
4bce7645   zhigang.li   make menu support...
80
                      this.dispatch('Submenu', 'on-update-active-name', name);
fd1582c5   梁灏   support Menu & La...
81
82
83
84
                  } else {
                      this.active = false;
                  }
              });
e05d7289   梁灏   update Menu
85
          }
b0893113   jingsam   :art: add eslint
86
87
      };
  </script>