index.js 843 B

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