space 动态布局组件(vue3-ts、setup)

动态布局组件

演示效果
效果图

使用方法

<Space :list="data" :ws="20" :hs="20" :x="3">
  <template #item="{ item, index }">
    <div clss="color-bg-3">
      <span class="color-font-0">{{ item.a }}</span><br/>
      <span class="color-font-0">{{ item.b }}</span><br/>
    </div>
  </template>
</Space>

import Space from '@/components/space/index.vue';

开发源码

<template>
  <ul
    class="space_ul flex-row"
    :style="{
      'padding-top': `${hs}px`,
      'padding-left': `${ws}px`
    }"
  >
    <li
      v-for="(item, index) in list"
      class="space_li"
      :style="{
        'flex': `0 0 ${100 / x}%`,
        'width': `calc(100% - ${ws*(x+1) / x}px)`,
        'padding-right': `${ws}px`,
        'padding-bottom': `${hs}px`,
      }"
    >
      <slot name="item" v-bind="{item, index}"></slot>
    </li>
  </ul>
</template>

<script setup lang="ts">
import { defineProps, defineEmits } from "vue";

// 使用
const props = defineProps<{
  list: Array<any>; // 渲染数据
  ws: number; // 宽度间距
  hs: number; // 高度间距
  x: number;  // 每行个数
}>();
</script>

<style lang="scss" scoped>
.space_ul {
  display: flex;
  flex-wrap: wrap;
}
.space_li {}
</style>
posted @   qoon  阅读(108)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示