index.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <script>
  2. import { computed, ref,useSlots,h } from 'vue-demi'
  3. export default {
  4. name: "mSpace",
  5. props: {
  6. direction: {
  7. type: String,
  8. default: 'horizontal'
  9. },
  10. size: [Number,String]
  11. },
  12. setup(props) {
  13. const $slot = useSlots();
  14. const slotList = ref([]);
  15. const styles = computed(() => {
  16. return {
  17. margin: `0 ${props.size}px ${props.size}px 0`
  18. }
  19. })
  20. $slot.default().forEach(item => {
  21. slotList.value.push(
  22. h(
  23. 'div',
  24. {
  25. className: 'm-space-item',
  26. style: styles.value
  27. },
  28. item
  29. )
  30. )
  31. })
  32. return () => [
  33. h(
  34. "div",
  35. {
  36. className: `m-space-box m-space-${props.direction}`
  37. },
  38. slotList.value
  39. )
  40. ]
  41. }
  42. }
  43. </script>
  44. <style lang="scss" scoped>
  45. .m-space-box{
  46. width: 100%;
  47. display: inline-flex;
  48. gap: 10px;
  49. flex-direction: inherit;
  50. flex-wrap: wrap;
  51. margin-bottom: 15px;
  52. }
  53. .m-space-vertical{
  54. flex-direction: column;
  55. width: fit-content;
  56. }
  57. .m-space-item{
  58. width:fit-content;
  59. }
  60. </style>