fs-grid.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <view class="fs-grid" :class="{ 'fs-grid-border': border }" :style="styleStr"><slot></slot></view>
  3. </template>
  4. <script>
  5. /**
  6. * 宫格组件
  7. * @description 宫格组件
  8. * @property {Number, String} gutter 间距
  9. * @property {Number} columnNum 列数量
  10. * @property {Boolean} padding 网格项内边距
  11. * @property {String} bgColor 背景色
  12. * @property {Boolean} border 是否显示边框
  13. * @property {Boolean} radius 是否圆角
  14. */
  15. export default {
  16. name: 'fs-grid'
  17. }
  18. </script>
  19. <script setup>
  20. import { computed, provide } from 'vue'
  21. const props = defineProps({
  22. gutter: {
  23. type: [Number, String],
  24. default: 0
  25. },
  26. border: Boolean,
  27. columnNum: {
  28. type: Number,
  29. default: 3
  30. },
  31. padding: {
  32. type: Boolean,
  33. default: true
  34. },
  35. bgColor: {
  36. type: String,
  37. default: '#fff'
  38. },
  39. radius: Boolean
  40. })
  41. const styleStr = computed(() => {
  42. return `grid-template-columns: repeat(${props.columnNum},1fr);gap:${props.gutter};`
  43. })
  44. provide('fsGrid', props)
  45. provide('gridBorder', props.border)
  46. provide('gridPadding', props.padding)
  47. provide('gridBgColor', props.bgColor)
  48. </script>
  49. <style lang="scss" scoped>
  50. .fs-grid {
  51. display: grid;
  52. &-border {
  53. border: 1px solid var(--border-color);
  54. border-bottom: none;
  55. }
  56. }
  57. </style>