Python私教张大鹏 Vue3整合AntDesignVue之Layout布局
最编程
2024-06-08 07:11:30
...
案例:栅格布局
核心代码:
<template>
<a-row>
<a-col :span="24">col</a-col>
</a-row>
<a-row>
<a-col :span="12">col-12</a-col>
<a-col :span="12">col-12</a-col>
</a-row>
<a-row>
<a-col :span="8">col-8</a-col>
<a-col :span="8">col-8</a-col>
<a-col :span="8">col-8</a-col>
</a-row>
<a-row>
<a-col :span="6">col-6</a-col>
<a-col :span="6">col-6</a-col>
<a-col :span="6">col-6</a-col>
<a-col :span="6">col-6</a-col>
</a-row>
</template>
vue3示例:
<script setup="">
</script>
<template>
<a-row>
<a-col :span="24" class="bg-indigo-500 h-32">24</a-col>
</a-row>
<a-row>
<a-col :span="12" class="bg-red-500 h-32">24</a-col>
<a-col :span="12" class="bg-blue-500 h-32">24</a-col>
</a-row>
<a-row>
<a-col :span="8" class="bg-cyan-500 h-32">24</a-col>
<a-col :span="8" class="bg-yellow-500 h-32">24</a-col>
<a-col :span="8" class="bg-purple-500 h-32">24</a-col>
</a-row>
</template>
<style scoped>
</style>
案例:列偏移
核心代码:
<template>
<a-row>
<a-col :span="8">col-8</a-col>
<a-col :span="8" :offset="8">col-8</a-col>
</a-row>
<a-row>
<a-col :span="6" :offset="6">col-6 col-offset-6</a-col>
<a-col :span="6" :offset="6">col-6 col-offset-6</a-col>
</a-row>
<a-row>
<a-col :span="12" :offset="6">col-12 col-offset-6</a-col>
</a-row>
</template>
vue3示例:
<script setup="">
</script>
<template>
<a-row>
<a-col :span="8" class="h-32 bg-indigo-500">1</a-col>
<a-col :span="8" :offset="8" class="h-32 bg-red-500">2</a-col>
</a-row>
</template>
<style scoped>
</style>
案例:上中下布局
核心代码:
<a-layout>
<a-layout-header :style="headerStyle">Header</a-layout-header>
<a-layout-content :style="contentStyle">Content</a-layout-content>
<a-layout-footer :style="footerStyle">Footer</a-layout-footer>
</a-layout>
const headerStyle: CSSProperties = {
textAlign: 'center',
color: '#fff',
height: 64,
paddingInline: 50,
lineHeight: '64px',
backgroundColor: '#7dbcea',
};
const contentStyle: CSSProperties = {
textAlign: 'center',
minHeight: 120,
lineHeight: '120px',
color: '#fff',
backgroundColor: '#108ee9',
};
const siderStyle: CSSProperties = {
textAlign: 'center',
lineHeight: '120px',
color: '#fff',
backgroundColor: '#3ba0e9',
};
const footerStyle: CSSProperties = {
textAlign: 'center',
color: '#fff',
backgroundColor: '#7dbcea',
};
vue3示例:
<script setup>
const headerStyle = {
textAlign: "center",
color: "#fff",
height: "64px",
paddingInline: 50,
lineHeight: "64px",
backgroundColor: "#7dbcea"
}
const contentStyle = {
textAlign: "center",
minHeight: "570px",
color: "#fff",
backgroundColor: "#108ee9"
}
const footerStyle = {
textAlign: "center",
color: "#fff",
backgroundColor: "#7dbcea"
}
</script>
<template>
<a-layout>
<a-layout-header :style="headerStyle">头部</a-layout-header>
<a-layout-content :style="contentStyle">内容</a-layout-content>
<a-layout-footer :style="footerStyle">底部</a-layout-footer>
</a-layout>
</template>
<style scoped>
</style>
案例:上左右下布局
核心代码:
<a-layout>
<a-layout-header :style="headerStyle">Header</a-layout-header>
<a-layout>
<a-layout-sider :style="siderStyle">Sider</a-layout-sider>
<a-layout-content :style="contentStyle">Content</a-layout-content>
</a-layout>
<a-layout-footer :style="footerStyle">Footer</a-layout-footer>
</a-layout>
const headerStyle: CSSProperties = {
textAlign: 'center',
color: '#fff',
height: 64,
paddingInline: 50,
lineHeight: '64px',
backgroundColor: '#7dbcea',
};
const contentStyle: CSSProperties = {
textAlign: 'center',
minHeight: 120,
lineHeight: '120px',
color: '#fff',
backgroundColor: '#108ee9',
};
const siderStyle: CSSProperties = {
textAlign: 'center',
lineHeight: '120px',
color: '#fff',
backgroundColor: '#3ba0e9',
};
const footerStyle: CSSProperties = {
textAlign: 'center',
color: '#fff',
backgroundColor: '#7dbcea',
};
vue3示例:
<script setup>
const headerStyle = {
height: "64px",
lineHeight: "64px",
color: "#fff",
backgroundColor: "#7dbcea",
textAlign: "center",
}
const sideStyle = {
minHeight: "570px",
backgroundColor: "#3ba0e9"
}
const footerStyle = {
textAlign: "center",
color:"#fff",
backgroundColor:"#7dbcea"
}
</script>
<template>
<a-layout>
<a-layout-header :style="headerStyle">头部</a-layout-header>
<a-layout>
<a-layout-sider :style="sideStyle">侧边</a-layout-sider>
<a-layout-content>内容</a-layout-content>
</a-layout>
<a-layout-footer :style="footerStyle">底部</a-layout-footer>
</a-layout>
</template>
实战:后台管理系统布局
核心代码:
<template>
<a-layout class="layout">
<a-layout-header>
<div class="logo" />
<a-menu
v-model:selectedKeys="selectedKeys"
theme="dark"
mode="horizontal"
:style="{ lineHeight: '64px' }"
>
<a-menu-item key="1">nav 1</a-menu-item>
<a-menu-item key="2">nav 2</a-menu-item>
<a-menu-item key="3">nav 3</a-menu-item>
</a-menu>
</a-layout-header>
<a-layout-content style="padding: 0 50px">
<a-breadcrumb style="margin: 16px 0">
<a-breadcrumb-item>Home</a-breadcrumb-item>
<a-breadcrumb-item>List</a-breadcrumb-item>
<a-breadcrumb-item>App</a-breadcrumb-item>
</a-breadcrumb>
<div :style="{ background: '#fff', padding: '24px', minHeight: '280px' }">Content</div>
</a-layout-content>
<a-layout-footer style="text-align: center">
Ant Design ©2018 Created by Ant UED
</a-layout-footer>
</a-layout>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
const selectedKeys = ref<string[]>(['2']);
</script>
<style scoped>
.site-layout-content {
min-height: 280px;
padding: 24px;
background: #fff;
}
#components-layout-demo-top .logo {
float: left;
width: 120px;
height: 31px;
margin: 16px 24px 16px 0;
background: rgba(255, 255, 255, 0.3);
}
.ant-row-rtl #components-layout-demo-top .logo {
float: right;
margin: 16px 0 16px 24px;
}
[data-theme='dark'] .site-layout-content {
background: #141414;
}
</style>
vue3代码:
<script setup>
import {ref} from 'vue';
const selectedKeys = ref(['2']);
</script>
<template>
<a-layout class="layout">
<!--头部-->
<a-layout-header>
<div class="logo"/>
<a-menu
v-model:selectedKeys="selectedKeys"
theme="dark"
mode="horizontal"
下一篇:
网络空间安全数学基础·同余式