Ant Design 还有react版本的
element —ui和Ant Design of Vue —UI类似
element的研发团队解散了,不在更新维护。
ui界面设计,把一些界面内容(样式)统一提供
地址:https://www.antdv.com/components/layout-cn/
支持环境
npm install ant-design-vue@1.7.8
<a name="iGr7n"></a>
# 使用
<a name="ltYsd"></a>
## 注册
```javascript
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// 引入ui库
import Antd from 'ant-design-vue';
// 引入ui库的样式
import 'ant-design-vue/dist/antd.css';
Vue.config.productionTip = false
// 将Antd注册成组件
Vue.use(Antd)
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
主要代码
<template>
<a-layout id="components-layout-demo-custom-trigger">
<a-layout-sider v-model="collapsed" :trigger="null" collapsible>
<div class="logo" :style="{fontSize:style}">财猫双犬</div>
<a-menu
class="a-emnu-back"
mode="inline"
:default-selected-keys="['1']" //当前被选中的选项卡
:default-open-keys="['sub1']" // 更具key关键字展开或折叠选项卡
:style="{ height: '100%', borderRight: 0 }"
>
<a-sub-menu key="sub1">
<span slot="title"><a-icon type="user" /><i class="show" v-show="!collapsed">系统账号管理</i></span>
<a-menu-item key="1">
平台账号管理
</a-menu-item>
<a-menu-item key="2">
角色管理
</a-menu-item>
<a-menu-item key="3">
权限列表
</a-menu-item>
<a-menu-item key="4">
部门列表
</a-menu-item>
</a-sub-menu>
<a-sub-menu key="sub2">
<span slot="title"><a-icon type="laptop" /><i class="show" v-show="!collapsed">用户管理</i></span>
<a-menu-item key="5">
option5
</a-menu-item>
<a-menu-item key="6">
option6
</a-menu-item>
<a-menu-item key="7">
option7
</a-menu-item>
<a-menu-item key="8">
option8
</a-menu-item>
</a-sub-menu>
<a-sub-menu key="sub3">
<span slot="title"><a-icon type="notification" /><i class="show" v-show="!collapsed">圈子管理</i></span>
<a-menu-item key="9" >
option9
</a-menu-item>
<a-menu-item key="10">
option10
</a-menu-item>
<a-menu-item key="11">
option11
</a-menu-item>
<a-menu-item key="12">
option12
</a-menu-item>
</a-sub-menu>
</a-menu>
</a-layout-sider>
<a-layout>
<a-layout-header style="background: #fff; padding: 0">
<a-icon
class="trigger"
:type="collapsed ? 'menu-unfold' : 'menu-fold'"
@click="change"
/>
</a-layout-header>
<a-breadcrumb class="a-breadcrumb-title" style="margin: 16px 0">
<a-breadcrumb-item style="fontSize: 20px">Home</a-breadcrumb-item>
<a-breadcrumb-item style="fontSize: 18px">List</a-breadcrumb-item>
<a-breadcrumb-item>App</a-breadcrumb-item>
</a-breadcrumb>
<a-layout-content
:style="{ margin: '24px 16px', padding: '24px', background: '#fff', minHeight: '280px' }"
>
<div class="a-layout-content-search-box">
<input placeholder="支持搜索用户名/姓名/手机号" />
<span class="a-layout-content-search">搜索</span>
<span class="a-dropdown-span">账号类型</span>
<a-dropdown class="a-dropdown">
<a class="ant-dropdown-link" @click="e => e.preventDefault()">
全部 <a-icon type="down" />
</a>
<a-menu slot="overlay">
<a-menu-item>
<a href="javascript:;">全部</a>
</a-menu-item>
<a-menu-item>
<a href="javascript:;">2nd menu item</a>
</a-menu-item>
<a-menu-item>
<a href="javascript:;">3rd menu item</a>
</a-menu-item>
</a-menu>
</a-dropdown>
</div>
<div class="a-button-account">
<a-button type="primary">
添加账户
</a-button>
</div>
<a-table :columns="columns" :data-source="data">
<!-- slot与columns中ID这一列中的slots匹配 -->
<span slot="customTitle"><a-icon type="smile-o" /> ID</span>
<!-- 通过slot与columns中的scopedSlots中的属性 customRender 设置相同值,以此来达成绑定 -->
<!-- 绑定后就可以通过slot-scope来定义数据, 变量1--当前数据 变量2--总数据 变量3--索引-->
<!-- <span slot="username" slot-scope="test,record,index">{{test}}--{{record}}--{{index}}</span> -->
<span slot="username" slot-scope="test">{{test}}</span>
<!-- 如果不需要通过scopedSlots中的属性 customRender来设置复杂数据,可以不用写对应的列标签,如下 -->
<!-- 即只需要为特殊的数据列写一个标签,用与设置数据,其余不用管也可以显示数据 -->
<!-- <span slot="name"></span>
<span slot="role"></span>
<span slot="sub"></span>
<span slot="phone"></span>
<span slot="state"></span>
<span slot="createdata"></span>-->
<!-- dataIndex: 'key',scopedSlots: { customRender: 'key' } 这两个都设置为key时-->
<!-- 可以通过slot-scope获取到key的值了 -->
<button slot="key" slot-scope="index">删除{{index}}</button>
</a-table>
</a-layout-content>
</a-layout>
</a-layout>
</template>
<script>
// colums中每一个对象代表一列,也只渲染这一列
// title代表表头信息
// scopedSlots用来渲染复杂数据,在上面的标签中通过给slot输入一个与customRender值相同的数据来绑定对应列
const columns = [
{
// dataIndex对应数据中,ID那一列的数据
dataIndex: 'ID',
key: 'ID',
// 通过slots设置title时,上面又将slot的值设置为slots中的title一样,这样就可以通过这样的设置给这一列的标题添加一些图标等
slots: { title: 'customTitle' },
// title:'ID',
// scopedSlots: { customRender: 'ID' },
},
{
// 当未写dataIndex时,如果有scopedSlots,那么显示的数据将会是当前所有数据
title: '用户名',
dataIndex: 'username',
key: 'username',
scopedSlots: { customRender: 'username' },
},
{
title: '姓名',
dataIndex: 'name',
key: 'name',
},
{
title: '角色',
key: 'role',
dataIndex: 'role',
// scopedSlots: { customRender: 'role' },
},
{
title: '部门',
key: 'sub',
dataIndex: 'sub',
// scopedSlots: { customRender: 'sub' },
},
{
title: '手机号',
key: 'phone',
dataIndex: 'phone',
// scopedSlots: { customRender: 'phone' },
},
{
title: '部门',
dataIndex: 'state',
key: 'state',
},
{
title: '创建时间',
dataIndex: 'createdata',
key: 'createdata',
},
{
title: '操作',
key: 'control',
dataIndex: 'key',
scopedSlots: { customRender: 'key' },
}
];
const data = [
{
key: '1',
ID:1,
username:'zhangsan',
name: '张三',
role: 'people',
sub: '英雄联盟',
phone: 136546548,
state:'hb( ̄▽ ̄)d ',
createdata:'2022.3.24',
},
{
key: '2',
ID:2,
username:'zhangsan',
name: '张三',
role: 'people',
sub: '英雄联盟',
phone: 136546548,
state:'hb( ̄▽ ̄)d ',
createdata:'2022.3.24',
},
{
key: '3',
ID:3,
username:'zhangsan',
name: '张三',
role: 'people',
sub: '英雄联盟',
phone: 136546548,
state:'hb( ̄▽ ̄)d ',
createdata:'2022.3.24',
},
];
export default {
data() {
return {
collapsed: false,
style:'20px',
data,
columns,
};
},
methods:{
change(){
this.collapsed = !this.collapsed;
if(this.style === '20px'){
this.style = '12px'
}else{
this.style = '20px'
}
}
}
}
</script>
<style>
#components-layout-demo-custom-trigger .trigger {
font-size: 18px;
line-height: 64px;
padding: 0 24px;
cursor: pointer;
transition: color 0.3s;
}
#components-layout-demo-custom-trigger .trigger:hover {
color: #1890ff;
}
#components-layout-demo-custom-trigger .logo {
height: 32px;
background: rgba(255, 255, 255, 0.2);
margin: 16px;
text-align: center;
color: #FFf;
line-height: 32px;
font-weight: bold;
font-size: 20px;
}
#components-layout-demo-custom-trigger .show {
text-overflow: ellipsis;
}
#components-layout-demo-custom-trigger .a-breadcrumb-title {
padding-left: 24px;
}
#components-layout-demo-custom-trigger .a-layout-content-search-box {
display: flex;
cursor: pointer;
}
#components-layout-demo-custom-trigger .a-layout-content-search-box input {
width: 350px;
height: 30px;
border-radius: 15px;
padding: 5px 35px;
box-sizing: border-box;
outline: none;
border: none;
background-color: #F0F2F5;
margin-right: 20px;
}
#components-layout-demo-custom-trigger .a-layout-content-search-box .a-layout-content-search {
color: #1890ff;
line-height: 30px;
}
#components-layout-demo-custom-trigger .a-layout-content-search-box .a-dropdown {
position: relative;
right: -50%;
top: 0;
display: flex;
align-items: center;
color: #333;
}
#components-layout-demo-custom-trigger .a-layout-content-search-box .a-dropdown-span {
position: relative;
right: -48%;
top: 0;
display: flex;
align-items: center;
}
#components-layout-demo-custom-trigger .a-layout-content-search-box + .a-button-account {
margin: 20px;
}
</style>