Sanakey
2021-01-31 53cc6f817625897935fb10c3845ad7be400f3036
src/vant-weapp/row/index.js
@@ -1,39 +1,22 @@
import { VantComponent } from '../common/component';
import { useChildren } from '../common/relation';
VantComponent({
  relation: {
    name: 'col',
    type: 'descendant',
    current: 'row',
    linked(target) {
      if (this.data.gutter) {
        target.setGutter(this.data.gutter);
      }
    },
  },
  relation: useChildren('col', function (target) {
    const { gutter } = this.data;
    if (gutter) {
      target.setData({ gutter });
    }
  }),
  props: {
    gutter: {
      type: Number,
      observer: 'setGutter',
    },
  },
  data: {
    viewStyle: '',
  },
  mounted() {
    if (this.data.gutter) {
      this.setGutter();
    }
  },
  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);
      this.children.forEach((col) => {
        col.setData(this.data);
      });
    },
  },