index.js 866 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { VantComponent } from '../common/component';
  2. VantComponent({
  3. relation: {
  4. name: 'col',
  5. type: 'descendant',
  6. linked: function 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: function mounted() {
  19. if (this.data.gutter) {
  20. this.setGutter();
  21. }
  22. },
  23. methods: {
  24. setGutter: function setGutter() {
  25. var _this = this;
  26. var gutter = this.data.gutter;
  27. var margin = "-" + Number(gutter) / 2 + "px";
  28. var style = gutter ? "margin-right: " + margin + "; margin-left: " + margin + ";" : '';
  29. this.set({
  30. style: style
  31. });
  32. this.getRelationNodes('../col/index').forEach(function (col) {
  33. col.setGutter(_this.data.gutter);
  34. });
  35. }
  36. }
  37. });