前端组件库——Arco Design Vue知识点大全(二)

简介: 教程来源 https://bncne.cn/sheyinggoutu.html Arco Design Vue提供丰富UI组件(按钮、栅格、表单、表格、反馈)及强大主题定制能力:支持Less编译时覆盖(如`arcoblue-6`主色生成10阶色板)与CSS变量运行时动态换肤,兼顾开发效率与用户体验。

三、核心组件详解

3.1 按钮组件 Button
按钮是用户交互中最基础的组件,Arco Design Vue提供了丰富的按钮样式和状态。

<template>
  <div>
    <!-- 按钮类型 -->
    <a-space>
      <a-button>默认按钮</a-button>
      <a-button type="primary">主要按钮</a-button>
      <a-button type="secondary">次要按钮</a-button>
      <a-button type="dashed">虚线按钮</a-button>
      <a-button type="text">文本按钮</a-button>
      <a-button type="outline">线框按钮</a-button>
    </a-space>

    <!-- 按钮状态 -->
    <a-space>
      <a-button status="danger">危险按钮</a-button>
      <a-button status="warning">警告按钮</a-button>
      <a-button status="success">成功按钮</a-button>
      <a-button disabled>禁用按钮</a-button>
      <a-button loading>加载中</a-button>
    </a-space>

    <!-- 按钮尺寸 -->
    <a-space>
      <a-button size="mini">迷你按钮</a-button>
      <a-button size="small">小型按钮</a-button>
      <a-button>默认按钮</a-button>
      <a-button size="large">大型按钮</a-button>
    </a-space>

    <!-- 长按钮(宽度100%) -->
    <a-button long type="primary">长按钮</a-button>

    <!-- 圆形按钮(用于图标) -->
    <a-button shape="circle" type="primary">
      <template #icon><icon-search /></template>
    </a-button>
  </div>
</template>

<script setup>
import { IconSearch } from '@arco-design/web-vue/es/icon'
</script>

按钮类型说明:Arco Design Vue提供了6种按钮类型。其中primary用于主要操作,secondary用于次要操作,dashed用于虚线边框的辅助操作,text用于轻量化操作,outline用于线框风格的辅助操作。status属性用于表示操作结果状态(成功/警告/危险)。

3.2 栅格系统 Grid
Arco Design Vue的栅格系统基于24列设计,通过Row和Col组件组合实现响应式布局。

<template>
  <!-- 基础栅格 -->
  <a-row :gutter="16">
    <a-col :span="12">
      <div class="grid-content">占12列</div>
    </a-col>
    <a-col :span="12">
      <div class="grid-content">占12列</div>
    </a-col>
  </a-row>

  <!-- 响应式栅格 -->
  <a-row :gutter="[16, 24]">
    <a-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4">
      <div class="grid-content">响应式内容</div>
    </a-col>
    <a-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4">
      <div class="grid-content">响应式内容</div>
    </a-col>
    <a-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4">
      <div class="grid-content">响应式内容</div>
    </a-col>
  </a-row>

  <!-- 列偏移 -->
  <a-row>
    <a-col :span="6" :offset="6">
      <div class="grid-content">偏移6列</div>
    </a-col>
  </a-row>

  <!-- 列排序 -->
  <a-row>
    <a-col :span="18" :push="6">
      <div class="grid-content">右侧内容</div>
    </a-col>
    <a-col :span="6" :pull="18">
      <div class="grid-content">左侧内容</div>
    </a-col>
  </a-row>
</a-row>

image.png
3.3 表单组件 Form
表单是企业级应用中最常用的组件之一,Arco Design Vue提供了完整的表单解决方案。

<template>
  <a-form
    ref="formRef"
    :model="formData"
    :rules="rules"
    layout="vertical"
    size="large"
  >
    <a-form-item field="username" label="用户名" required>
      <a-input
        v-model="formData.username"
        placeholder="请输入用户名"
        allow-clear
      />
    </a-form-item>

    <a-form-item field="email" label="邮箱" required>
      <a-input
        v-model="formData.email"
        placeholder="请输入邮箱"
        allow-clear
      />
    </a-form-item>

    <a-form-item field="role" label="角色" required>
      <a-select
        v-model="formData.role"
        placeholder="请选择角色"
        allow-clear
      >
        <a-option value="admin">管理员</a-option>
        <a-option value="user">普通用户</a-option>
      </a-select>
    </a-form-item>

    <a-form-item field="status" label="状态">
      <a-switch v-model="formData.status" />
    </a-form-item>

    <a-form-item>
      <a-space>
        <a-button type="primary" html-type="submit">提交</a-button>
        <a-button @click="handleReset">重置</a-button>
      </a-space>
    </a-form-item>
  </a-form>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { Message } from '@arco-design/web-vue'

const formRef = ref()

const formData = reactive({
  username: '',
  email: '',
  role: '',
  status: false
})

// 表单验证规则
const rules = {
  username: [
    { required: true, message: '请输入用户名' },
    { minLength: 3, maxLength: 20, message: '长度在3-20个字符' }
  ],
  email: [
    { required: true, message: '请输入邮箱' },
    { type: 'email', message: '请输入正确的邮箱格式' }
  ],
  role: [
    { required: true, message: '请选择角色' }
  ]
}

const handleReset = () => {
  formRef.value.resetFields()
}

const handleSubmit = () => {
  formRef.value.validate().then(() => {
    Message.success('提交成功')
  }).catch(() => {
    Message.error('请正确填写表单')
  })
}
</script>

3.4 数据表格组件 Table
表格是中后台系统中最复杂的组件之一,Arco Design Vue的Table组件功能强大。

<template>
  <a-table
    :columns="columns"
    :data="tableData"
    :pagination="pagination"
    :loading="loading"
    row-key="id"
    stripe
    border
    :row-selection="rowSelection"
    @page-change="handlePageChange"
    @page-size-change="handlePageSizeChange"
  >
    <!-- 自定义列内容 -->
    <template #status="{ record }">
      <a-tag :color="record.status === 1 ? 'green' : 'red'">
        {
  { record.status === 1 ? '启用' : '禁用' }}
      </a-tag>
    </template>

    <template #operations="{ record }">
      <a-space>
        <a-button type="text" size="small" @click="handleEdit(record)">编辑</a-button>
        <a-button type="text" status="danger" size="small" @click="handleDelete(record)">删除</a-button>
      </a-space>
    </template>
  </a-table>
</template>

<script setup>
import { ref } from 'vue'
import { Message } from '@arco-design/web-vue'

const columns = [
  {
    title: 'ID',
    dataIndex: 'id',
    width: 80,
    fixed: 'left'
  },
  {
    title: '姓名',
    dataIndex: 'name',
    width: 120,
    sortable: {
      sortDirections: ['ascend', 'descend']
    }
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 100,
    slotName: 'status'
  },
  {
    title: '操作',
    slotName: 'operations',
    width: 150,
    fixed: 'right'
  }
]

const tableData = ref([])
const loading = ref(false)
const pagination = ref({
  current: 1,
  pageSize: 20,
  total: 0,
  showTotal: true,
  showJumper: true,
  showPageSize: true
})
</script>

3.5 反馈组件
消息通知 Message

<script setup>
import { Message } from '@arco-design/web-vue'

// 基础消息
Message.info('这是一条信息')
Message.success('操作成功')
Message.warning('警告信息')
Message.error('操作失败')

// 带配置的消息
Message.success({
  content: '自定义消息',
  duration: 3000,
  closable: true
})
</script>

对话框 Modal

<template>
  <a-button @click="visible = true">打开对话框</a-button>

  <a-modal
    v-model:visible="visible"
    title="对话框标题"
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <p>这是对话框的内容</p>
    <p>可以放置任意自定义内容</p>
  </a-modal>
</template>

<script setup>
import { ref } from 'vue'
import { Message } from '@arco-design/web-vue'

const visible = ref(false)

const handleOk = () => {
  Message.success('点击了确定')
  visible.value = false
}

const handleCancel = () => {
  Message.info('点击了取消')
}
</script>

抽屉 Drawer

<template>
  <a-button @click="drawerVisible = true">打开抽屉</a-button>

  <a-drawer
    v-model:visible="drawerVisible"
    title="抽屉标题"
    width="400"
    @ok="handleDrawerOk"
    @cancel="handleDrawerCancel"
  >
    <p>这是抽屉的内容</p>
    <p>抽屉适合放置需要较多空间的内容</p>
  </a-drawer>
</template>

四、主题定制

Arco Design Vue提供了强大的主题定制能力,支持两种主题定制方式:CSS变量覆盖和Less变量覆盖。

4.1 主题定制原理
Arco Design使用Palette色彩工具将6号色作为色板中的主色,分为10个梯度(arcoblue-1到arcoblue-10)。其中arcoblue-6是主色,定制的颜色会自动生成从1到10的完整色板。

// 定制主题时,修改arcoblue-6即可,其他梯度会自动生成
modifyVars: {
  'arcoblue-6': '#165DFF'  // 设置主色,自动生成1-10号色
}

4.2 通过Less变量定制(编译时)
步骤1:安装Less支持

npm install -D less

步骤2:配置Vite

// vite.config.ts
export default defineConfig({
  css: {
    preprocessorOptions: {
      less: {
        modifyVars: {
          'arcoblue-6': '#165DFF',      // 主题主色
          'border-radius-none': '0',
          'border-radius-small': '2px',
          'border-radius-medium': '4px',
          'border-radius-large': '8px',
          'border-radius-circle': '50%'
        },
        javascriptEnabled: true,         // 必须启用
        additionalData: '@import "@/styles/variables.less";'  // 可选:导入公共变量
      }
    }
  }
})

步骤3:引入Less源文件

// main.js
import { createApp } from 'vue'
import ArcoVue from '@arco-design/web-vue'
import '@arco-design/web-vue/dist/arco.less'  // 注意:引入.less文件而非.css

const app = createApp(App)
app.use(ArcoVue)
app.mount('#app')

4.3 通过CSS变量定制(运行时)
Arco Design Vue也支持通过CSS变量进行运行时主题切换,无需重新编译:

<template>
  <a-config-provider :theme="theme">
    <app />
  </a-config-provider>
</template>

<script setup>
import { reactive } from 'vue'

// 动态主题配置
const theme = reactive({
  token: {
    colorPrimary: '#7c3aed',      // 主题主色
    colorSuccess: '#10b981',       // 成功色
    colorWarning: '#f59e0b',       // 警告色
    colorError: '#ef4444',         // 错误色
    borderRadius: '8px',           // 圆角
    fontSize: '14px'               // 字体大小
  }
})

// 运行时动态修改主题色
const changeTheme = (color) => {
  theme.token.colorPrimary = color
}
</script>

CSS变量方式的特点:支持运行时动态切换,无需重新编译,适合需要支持多主题的场景。但需要注意,CSS变量的动态修改在低版本浏览器中可能存在兼容性问题。

4.4 常用主题变量
image.png
来源:
https://bncne.cn/xiangjicanshu.html

相关文章
|
2月前
|
人工智能 测试技术 API
阿里云 MSE AI Registry 公测开启:给你的 AI 资产一个专属的注册中心
AI Registry 公测开启,一文了解产品能力、AgentLoop 集成与 Skill 规划。
354 34
|
2月前
|
安全 Java 程序员
python进程、线程、协程
multiprocessing是python的多进程管理包,和threading.Thread类似。
160 4
|
13天前
|
人工智能 Linux API
全平台零门槛:Win11、Mac、Linux 通用 Hermes Agent 安装教程
Hermes Agent是Nous Research开源的自进化AI助手(MIT协议),越用越懂你。支持多工具并行、自动记忆习惯,Python编写,v0.13.0版。兼容Win/macOS/Linux/Docker,国内用户可配清华镜像快速部署,需API密钥(如Kimi)。
|
2月前
|
编解码 人工智能 监控
阿里云百炼大模型HappyHorse介绍:功能与用途、适用场景与使用教程参考
阿里云百炼HappyHorse大模型服务平台,为用户提供文生视频、图生视频、参考生视频及视频编辑四大功能,支持高质量视频生成,适配广告、电商等多场景。该平台支持720P/1080P分辨率、3-15秒时长输出,具备有声支持、地域一致性校验及按秒计费(0.9元/秒起)等技术特性。用户可免费体验10秒视频生成,通过API配置实现智能创作,并遵循详细教程与地域化调用规范,高效完成视频生成与编辑工作流,赋能专业内容生产。
|
2月前
|
人工智能 弹性计算 安全
阿里云免费部署 Hermes Agent 教程:零门槛搭建自进化 AI 智能体
阿里云免费提供Hermes Agent一键部署方案:基于ECS、百炼大模型与计算巢,零代码、几分钟即可搭建开源自进化AI智能体。支持跨会话记忆、多平台接入、私有化部署,兼顾易用性与数据安全,个人提效与企业数字化皆适用。
|
2月前
|
人工智能 JavaScript 安全
零基础搞定OpenClaw(小龙虾)Windows安装与使用,附最新部署包
OpenClaw(小龙虾)是2026年热门开源AI智能体,本地运行、零代码、可视化,支持办公/开发自动化。隐私安全、5–10分钟一键部署,内置Git/Python/Node.js,适配Win10/11,支持微信/飞书联动与多模型切换。
1095 3
|
21天前
|
人工智能 架构师 测试技术
AI编程王炸组合:顶级三剑客 OpenSpec 定方向,Superpowers定纪律,Harness定协同
AI编程王炸组合:顶级三剑客 OpenSpec 定方向,Superpowers定纪律,Harness定协同
|
5天前
|
BI
OPD型员工的三个真实工作场景
OPC中国实践案例库收录三大真实场景:内容运营、客户成功、项目交付,均通过OPD模式(智能体协同)实现提效——内容产出增4倍、客户服务量扩4倍、项目经理聚焦高价值决策。无需规模门槛,小团队可快速试点,配套可复用模板与“智能体效能负责人”培养体系。(239字)