index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { VantComponent } from '../common/component';
  2. VantComponent({
  3. relation: {
  4. name: 'grid-item',
  5. type: 'descendant',
  6. linked(child) {
  7. this.children.push(child);
  8. },
  9. unlinked(child) {
  10. this.children = this.children.filter((item) => item !== child);
  11. }
  12. },
  13. props: {
  14. square: {
  15. type: Boolean,
  16. observer: 'updateChildren'
  17. },
  18. gutter: {
  19. type: [Number, String],
  20. value: 0,
  21. observer: 'updateChildren'
  22. },
  23. clickable: {
  24. type: Boolean,
  25. observer: 'updateChildren'
  26. },
  27. columnNum: {
  28. type: Number,
  29. value: 4,
  30. observer: 'updateChildren'
  31. },
  32. center: {
  33. type: Boolean,
  34. value: true,
  35. observer: 'updateChildren'
  36. },
  37. border: {
  38. type: Boolean,
  39. value: true,
  40. observer: 'updateChildren'
  41. }
  42. },
  43. beforeCreate() {
  44. this.children = [];
  45. },
  46. created() {
  47. const { gutter } = this.data;
  48. if (gutter) {
  49. this.setData({
  50. style: `padding-left: ${gutter}px`
  51. });
  52. }
  53. },
  54. methods: {
  55. updateChildren() {
  56. this.children.forEach((child) => {
  57. child.updateStyle();
  58. });
  59. }
  60. }
  61. });