index.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { link } from '../mixins/link';
  2. import { VantComponent } from '../common/component';
  3. VantComponent({
  4. relation: {
  5. name: 'grid',
  6. type: 'ancestor',
  7. linked(parent) {
  8. this.parent = parent;
  9. }
  10. },
  11. mixins: [link],
  12. props: {
  13. icon: String,
  14. dot: Boolean,
  15. info: null,
  16. text: String,
  17. useSlot: Boolean
  18. },
  19. mounted() {
  20. this.updateStyle();
  21. },
  22. methods: {
  23. updateStyle() {
  24. if (!this.parent) {
  25. return;
  26. }
  27. const { data, children } = this.parent;
  28. const { columnNum, border, square, gutter, clickable, center } = data;
  29. const width = `${100 / columnNum}%`;
  30. const styleWrapper = [];
  31. styleWrapper.push(`width: ${width}`);
  32. if (square) {
  33. styleWrapper.push(`padding-top: ${width}`);
  34. }
  35. if (gutter) {
  36. styleWrapper.push(`padding-right: ${gutter}px`);
  37. const index = children.indexOf(this);
  38. if (index >= columnNum) {
  39. styleWrapper.push(`margin-top: ${gutter}px`);
  40. }
  41. }
  42. this.setData({
  43. style: styleWrapper.join('; '),
  44. center,
  45. border,
  46. square,
  47. gutter,
  48. clickable
  49. });
  50. },
  51. onClick() {
  52. this.$emit('click');
  53. this.jumpLink();
  54. }
  55. }
  56. });