index.js 843 Bytes
Newer Older
李嘉林 committed
1 2
import { VantComponent } from '../common/component';
VantComponent({
程默 committed
3 4 5 6 7 8 9 10
  relation: {
    name: 'col',
    type: 'descendant',
    current: 'row',
    linked(target) {
      if (this.data.gutter) {
        target.setGutter(this.data.gutter);
      }
李嘉林 committed
11
    },
程默 committed
12 13 14 15 16
  },
  props: {
    gutter: {
      type: Number,
      observer: 'setGutter',
李嘉林 committed
17
    },
程默 committed
18 19 20 21 22 23 24
  },
  data: {
    viewStyle: '',
  },
  mounted() {
    if (this.data.gutter) {
      this.setGutter();
李嘉林 committed
25
    }
程默 committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39
  },
  methods: {
    setGutter() {
      const { gutter } = this.data;
      const margin = `-${Number(gutter) / 2}px`;
      const viewStyle = gutter
        ? `margin-right: ${margin}; margin-left: ${margin};`
        : '';
      this.setData({ viewStyle });
      this.getRelationNodes('../col/index').forEach((col) => {
        col.setGutter(this.data.gutter);
      });
    },
  },
李嘉林 committed
40
});