index.js 907B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { VantComponent } from '../common/component';
  2. VantComponent({
  3. relation: {
  4. name: 'col',
  5. type: 'descendant',
  6. linked(target) {
  7. if (this.data.gutter) {
  8. target.setGutter(this.data.gutter);
  9. }
  10. }
  11. },
  12. props: {
  13. gutter: Number
  14. },
  15. watch: {
  16. gutter: 'setGutter'
  17. },
  18. mounted() {
  19. if (this.data.gutter) {
  20. this.setGutter();
  21. }
  22. },
  23. methods: {
  24. setGutter() {
  25. const { gutter } = this.data;
  26. const margin = `-${Number(gutter) / 2}px`;
  27. const style = gutter
  28. ? `margin-right: ${margin}; margin-left: ${margin};`
  29. : '';
  30. this.set({ style });
  31. this.getRelationNodes('../col/index').forEach(col => {
  32. col.setGutter(this.data.gutter);
  33. });
  34. }
  35. }
  36. });