当前位置: 首页 > news >正文

后台数据管理系统 - 项目架构设计-Vue3+axios+Element-plus(0920)

十三、文章分类页面 - [element-plus 表格]

Git仓库:https://gitee.com/msyycn/vue3-hei-ma.git

基本架子 - PageContainer

功能需求说明:

  1. 基本架子-PageContainer封装
  2. 文章分类渲染 & loading处理
  3. 文章分类添加编辑[element-plus弹层]
  4. 文章分类删除
  1. 基本结构样式,用到了el-card 组件
<template><el-card class="page-container"><template #header><div class="header"><span>文章分类</span><div class="extra"><el-button type="primary">添加分类</el-button></div></div></template>...</el-card>
</template><style lang="scss" scoped>
.page-container {min-height: 100%;box-sizing: border-box;.header {display: flex;align-items: center;justify-content: space-between;}
}
</style>
  1. 考虑到多个页面复用,封装成组件
    • props 定制标题(父传子)
    • 默认插槽 default 定制内容主体
    • 具名插槽 extra 定制头部右侧额外的按钮
<script setup>
defineProps({title: {required: true,type: String}
})
</script><template><el-card class="page-container"><template #header><div class="header"><span>{{ title }}</span><div class="extra"><slot name="extra"></slot></div></div></template><slot></slot></el-card>
</template><style lang="scss" scoped>
.page-container {min-height: 100%;box-sizing: border-box;.header {display: flex;align-items: center;justify-content: space-between;}
}
</style>
  1. 页面中直接使用测试 ( unplugin-vue-components 会自动注册)
  • 文章分类测试:
<template><page-container title="文章分类"><template #extra><el-button type="primary"> 添加分类 </el-button></template>主体部分</page-container>
</template>
  • 文章管理测试:
<template><page-container title="文章管理"><template #extra><el-button type="primary">发布文章</el-button></template>主体部分</page-container>
</template>

视图预览请添加图片描述

文章分类渲染

封装API - 请求获取表格数据

  1. 新建 api/article.js 封装获取频道列表的接口
import request from '@/utils/request'
export const artGetChannelsService = () => request.get('/my/cate/list')
  1. 页面中调用接口,获取数据存储
const channelList = ref([])const getChannelList = async () => {const res = await artGetChannelsService()channelList.value = res.data.data
}
  1. ArticleChannel.vue
<script setup>
import { artGetChannelsService } from '@/api/article'
import {ref} from 'vue'const channelList = ref([]) // 文章分类列表
// 获取文章分类列表
const getChannelList = async () => {const res = await artGetChannelsService()channelList.value = res.data.dataconsole.log('文章分类列表',channelList.value);}// 调用获取文章分类列表
getChannelList()
</script><template><div><!-- 按需引入 --><page-container title="文章分类"> <!-- 右侧按钮 - 添加文章 - 具名插槽 --><template #extra><el-button>添加分类</el-button></template>主体部分--表格</page-container></div>
</template><style lang="scss" scoped>
</style>

视图预览

请添加图片描述

el-table 表格动态渲染

<el-table :data="channelList" style="width: 100%"><el-table-column label="序号" width="100" type="index"> </el-table-column><el-table-column label="分类名称" prop="cate_name"></el-table-column><el-table-column label="分类别名" prop="cate_alias"></el-table-column><el-table-column label="操作" width="100"><template #default="{ row }"><el-button:icon="Edit"circleplaintype="primary"@click="onEditChannel(row)"></el-button><el-button:icon="Delete"circleplaintype="danger"@click="onDelChannel(row)"></el-button></template></el-table-column><template #empty><el-empty description="没有数据" /></template>
</el-table>const onEditChannel = (row) => {console.log(row)
}
const onDelChannel = (row) => {console.log(row)
}

预览视图

请添加图片描述

el-table 表格 loading 效果

  1. 定义变量,v-loading绑定
const loading = ref(false)<el-table v-loading="loading">
  1. 发送请求前开启,请求结束关闭
const getChannelList = async () => {loading.value = trueconst res = await artGetChannelsService()channelList.value = res.data.dataloading.value = false
}

ArticleChannel.vue

<script setup>
import { artGetChannelsService } from '@/api/article'
import { Delete,Edit } from   '@element-plus/icons-vue'import {ref} from 'vue'const channelList = ref([]) // 文章分类列表
const loading = ref(false) //加载状态
// 获取文章分类列表
const getChannelList = async () => {// 发请求之前先将loading设置为trueloading.value = true// 调用接口const res = await artGetChannelsService()channelList.value = res.data.data// 发完请求,关闭loadingloading.value = false// console.log('文章分类列表',channelList.value);}// 调用获取文章分类列表
getChannelList()// 编辑文章分类
const onEditChannel =(row,$index) =>{
console.log(row,$index)}// 删除文章分类
const onDelChannel =(row,$index)=>{console.log(row,$index)}
</script><template><div><!-- 按需引入 --><page-container title="文章分类"> <!-- 右侧按钮 - 添加文章 - 具名插槽 --><template #extra><el-button>添加分类</el-button></template><!-- 主体部分--表格 --><el-table :data="channelList" style="width: 100%" v-loading="loading"><el-table-column   label="序号"    type="index"  width="100" ></el-table-column><el-table-column   label="分类名称" prop="cate_name" ></el-table-column><el-table-column   label="分类别名" prop="cate_alias" ></el-table-column><el-table-column   label="操作"      width="100"><template #default="{row,$index}"><el-button  @click="onEditChannel(row,$index)" plain :icon="Edit" circle type="primary" ></el-button><el-button  @click="onDelChannel(row,$index)" plain :icon="Delete" circle type="danger" ></el-button></template></el-table-column></el-table></page-container></div>
</template><style lang="scss" scoped>
</style>

请添加图片描述

请求到的数组为空时

 channelList.value = []

请添加图片描述

添加element-plus插槽:

     <!-- 主体部分--表格 --><el-table :data="channelList" style="width: 100%" v-loading="loading"><el-table-column   label="序号"    type="index"  width="100" ></el-table-column><el-table-column   label="分类名称" prop="cate_name" ></el-table-column><el-table-column   label="分类别名" prop="cate_alias" ></el-table-column><el-table-column   label="操作"      width="100"><template #default="{row,$index}"><el-button  @click="onEditChannel(row,$index)" plain :icon="Edit" circle type="primary" ></el-button><el-button  @click="onDelChannel(row,$index)" plain :icon="Delete" circle type="danger" ></el-button></template></el-table-column><!-- 没有数据 --><template #empty><el-empty description="暂无数据"></el-empty></template></el-table>

请添加图片描述
下期见!

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 十五、差分输入运算放大电路
  • 前端web端项目运行的时候没有ip访问地址
  • 【秋招笔试-支持在线评测】8.28华为秋招(已改编)-三语言题解
  • 20240921在友善之臂的NanoPC-T6开发板上确认宸芯的数传模块CX6602N的AT命令
  • etcd 集群搭建与测试指南
  • Linux入门学习:Linux调试器gdb使用
  • vue中 <template> 与 <template lang=“jade“>的对比,哪个性能好
  • 相机光学(三十八)——VCM(Voice Coil Motor)音圈马达
  • T4—猴痘识别
  • 计算总体方差statistics.pvariance()
  • 前端面试记录
  • 5. 数字证书与公钥基础设施
  • PAT甲级-1083 List Grades
  • 智能自行车码表:基于2605C语音芯片的创新开发方案
  • 简单水印通过python去除
  • 自己简单写的 事件订阅机制
  • 「面试题」如何实现一个圣杯布局?
  • Babel配置的不完全指南
  • django开发-定时任务的使用
  • dva中组件的懒加载
  • gcc介绍及安装
  • Invalidate和postInvalidate的区别
  • Mybatis初体验
  • PAT A1050
  • PHP变量
  • Synchronized 关键字使用、底层原理、JDK1.6 之后的底层优化以及 和ReenTrantLock 的对比...
  • webgl (原生)基础入门指南【一】
  • 百度贴吧爬虫node+vue baidu_tieba_crawler
  • 简单基于spring的redis配置(单机和集群模式)
  • 试着探索高并发下的系统架构面貌
  • 小而合理的前端理论:rscss和rsjs
  • 验证码识别技术——15分钟带你突破各种复杂不定长验证码
  • Android开发者必备:推荐一款助力开发的开源APP
  • 关于Kubernetes Dashboard漏洞CVE-2018-18264的修复公告
  • 好程序员web前端教程分享CSS不同元素margin的计算 ...
  • ​iOS实时查看App运行日志
  • #14vue3生成表单并跳转到外部地址的方式
  • (7)svelte 教程: Props(属性)
  • (动手学习深度学习)第13章 计算机视觉---图像增广与微调
  • (多级缓存)多级缓存
  • (官网安装) 基于CentOS 7安装MangoDB和MangoDB Shell
  • (三)Kafka离线安装 - ZooKeeper开机自启
  • (删)Java线程同步实现一:synchronzied和wait()/notify()
  • (算法)Travel Information Center
  • (一)基于IDEA的JAVA基础12
  • (最全解法)输入一个整数,输出该数二进制表示中1的个数。
  • **《Linux/Unix系统编程手册》读书笔记24章**
  • .bat文件调用java类的main方法
  • .NET / MSBuild 扩展编译时什么时候用 BeforeTargets / AfterTargets 什么时候用 DependsOnTargets?
  • .NET 中各种混淆(Obfuscation)的含义、原理、实际效果和不同级别的差异(使用 SmartAssembly)
  • .NET建议使用的大小写命名原则
  • .NET面试题解析(11)-SQL语言基础及数据库基本原理
  • .so文件(linux系统)
  • /bin/bash^M: bad interpreter: No such file or directory
  • @staticmethod和@classmethod的作用与区别