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>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?