在写代码之前, 我们先分析用到的知识点, 这是一个好习惯, 我们先分析下首页最顶部的4个”信息快”.
需求
实现首页顶部的4个”信息块”, 要求适配3种不同的分辨率.


用到的组件
响应布局(Row/Col)
用上节课学的栅格进行响应布局, 上面3种尺寸的响应, 根据对照表可以得出只需要使用“xs/sm/lg”即可.
<a-col :xs="24" :sm="12" :lg="6"></a-col>
卡片组件(Card)

这个白色的带阴影的矩形, 在”ant ui”中叫”Card组件”.
<a-card title="标题" :loading="isLoading" size="small">
<!-- 内容 -->
</a-card>
这节课我们只需要用到他的3个属性:
- “title”就是卡片头部的标题文字
- “loading”是Boolean值, 可以控制卡片的加载动画.
-
图标组件

“ant ui”集成了图标库, 常用的图标我们都可以在这里找到. 不过图标需要我们单独安装:npm install --save @ant-design/icons-vue
图标以组件的形式存在, 使用的时候需要引入每一个图标组件: 访问图标列表找自己需要的图标.
- 点击图标会自动复制图标组件名, 如:”
“
在我们的Home.vue中要引入并注册图标组件:
<script lang="ts">
import { defineComponent } from "vue";
import { CaretUpFilled, CaretDownFilled } from "@ant-design/icons-vue";
export default defineComponent({
name: "Home",
components: {
CaretUpFilled, CaretDownFilled
},
});
</script>
<template>
<CaretUpFilled/>
<CaretDownFilled/>
</template>
语义文字组件(Typography)

为了所有界面的颜色统一, ant对文字颜色也封装成了组件.
<a-typography-text>Ant Design Vue (default)</a-typography-text>
<a-typography-text type="secondary">Ant Design Vue (secondary)</a-typography-text>
<a-typography-text type="success">Ant Design Vue (success)</a-typography-text>
<a-typography-text type="warning">Ant Design Vue (warning)</a-typography-text>
<a-typography-text type="danger">Ant Design Vue (danger)</a-typography-text>
进度条组件(Progress)
“ant ui”中提供了进度条组件”Progress“, 其有3种形状, 可以通过参数”type”设置.
注意: ant中的组件默认都是全局注册的, 所以我们可以直接在组件的”template”中使用组件标签.

<a-progress type="dashboard" :percent="70" :width="70" />

<a-progress
:show-info="false"
:stroke-color="{
'0%': '#108ee9',
'100%': '#87d068',
}"
:percent="85"
/>
“show-info“用来控制进度文字是否在进度条尾部显示.
“stroke-color“用来定义背景的渐变色.

<a-progress :percent="70" :width="70" />
type的默认值是”circle”.

