Blame view

src/components/layout/row.vue 2.09 KB
7fa943eb   梁灏   init
1
  <template>
d2203972   梁灏   add gutter to Row...
2
      <div :class="classes" :style="styles">
7fa943eb   梁灏   init
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
          <slot></slot>
      </div>
  </template>
  <script>
      import { oneOf } from '../../utils/assist';
  
      const prefixCls = 'ivu-row';
  
      export default {
          props: {
              type: {
                  validator (value) {
                      return oneOf(value, ['flex']);
                  }
              },
              align: {
                  validator (value) {
                      return oneOf(value, ['top', 'middle', 'bottom']);
                  }
              },
              justify: {
                  validator (value) {
                      return oneOf(value, ['start', 'end', 'center', 'space-around', 'space-between']);
                  }
              },
d2203972   梁灏   add gutter to Row...
28
29
30
31
              gutter: {
                  type: Number,
                  default: 0
              },
7fa943eb   梁灏   init
32
33
34
35
36
37
38
39
40
41
42
43
44
              className: String
          },
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
                      {
                          [`${prefixCls}-${this.type}`]: !!this.type,
                          [`${prefixCls}-${this.type}-${this.align}`]: !!this.align,
                          [`${prefixCls}-${this.type}-${this.justify}`]: !!this.justify,
                          [`${this.className}`]: !!this.className
                      }
                  ]
d2203972   梁灏   add gutter to Row...
45
46
47
48
49
50
51
52
53
54
55
              },
              styles () {
                  let style = {};
                  if (this.gutter !== 0) {
                      style = {
                          marginLeft: this.gutter / -2 + 'px',
                          marginRight: this.gutter / -2 + 'px'
                      }
                  }
  
                  return style;
7fa943eb   梁灏   init
56
              }
d2203972   梁灏   add gutter to Row...
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
          },
          methods: {
              updateGutter (val) {
                  this.$children.forEach((child) => {
                      if (val !== 0) {
                          child.gutter = val;
                      }
                  });
              }
          },
          watch: {
              gutter (val) {
                  this.updateGutter(val);
              }
          },
          ready () {
              this.updateGutter(this.gutter);
7fa943eb   梁灏   init
74
75
76
          }
      }
  </script>