通过自定义模板列渲染后三列的表格
是否有效:cat_deleted true渲染成红色对勾 false 渲染成绿色对勾
vue-table-with-tree-grid/Example.vue at master · MisterTaki/vue-table-with-tree-grid · GitHub
type | 列类型,可选值有 'template'(自定义列模板) |
表格数据
{
label: '是否有效',//列标题名称
prop: 'cat_deleted',//对应列内容的属性名
width: '400px',
type:'template',//表示将当前列渲染成为模板列
template:'isok',//表示当前使用这一类使用的模板名称-再表格内容节点中使用
},
作用域插槽 显示 模板累列接收
<!-- 表格区域 tree-table和我们前面注册的自定义名称一样-->
<!-- data数据源cateList columns列配置 election-type除复选框 去除展开行expand-type show-index索引 index-text索引名称 border分割线 show-row-hover高亮效果-->
<tree-table :data="cateList" :columns="columns" :selection-type="false" :expand-type="false" show-index index-text="#" border :show-row-hover="false">
<!-- 在内容节点定义模板 -->
<template slot="isok" slot-scope="scope">
<i style="color: lightgreen;" class="el-icon-success" v-if="scope.row.cat_deleted===false"></i>
<i style="color: red;" class="el-icon-error" v-if="scope.row.cat_deleted===true"></i>
</template>
</tree-table>
实现效果
<template>
<div>
<!-- 面包屑导航区 -->
<el-breadcrumb separator-class="el-icon-arrow-right">
<el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
<el-breadcrumb-item>商品管理</el-breadcrumb-item>
<el-breadcrumb-item>商品分类</el-breadcrumb-item>
</el-breadcrumb>
<!-- 卡片视图区域 -->
<el-card class="box-card">
<el-row>
<el-col>
<el-button type="primary">添加分类</el-button>
</el-col>
</el-row>
<!-- 表格区域 tree-table和我们前面注册的自定义名称一样-->
<!-- data数据源cateList columns列配置 election-type除复选框 去除展开行expand-type show-index索引 index-text索引名称 border分割线 show-row-hover高亮效果-->
<tree-table :data="cateList" :columns="columns" :selection-type="false" :expand-type="false" show-index index-text="#" border :show-row-hover="false">
<!-- 在内容节点定义模板 -->
<template slot="isok" slot-scope="scope">
<i style="color: lightgreen;" class="el-icon-success" v-if="scope.row.cat_deleted===false"></i>
<i style="color: red;" class="el-icon-error" v-if="scope.row.cat_deleted===true"></i>
</template>
</tree-table>
<!-- 分页区域 -->
</el-card>
</div>
</template>
<script>
export default {
data() {
return {
cateList: [],//商品分类的数据列表 默认为空
queryInfo: {//查询条件
type: 3,//3级分类
pagenum: 1,//当前页码值
pagesize: 5//每页显示5条数据
},
total: 0,//总数据条数
columns: [//表格各列的配置
{
label: '分类名称',//列标题名称
prop: 'cat_name',//对应列内容的属性名
width: '400px',
},
{
label: '是否有效',//列标题名称
prop: 'cat_deleted',//对应列内容的属性名
width: '400px',
type:'template',//表示将当前列渲染成为模板列
template:'isok',//表示当前使用这一类使用的模板名称-再表格内容节点中使用
},
],
}
},
created() {//一开始进行获取数据
this.getCateList()//获取商品信息
},
methods: {
async getCateList() {//获取商品分类数据-涉及分页 查询条件
const { data: res } = await this.$http.get('categories', { params: this.queryInfo })
if (res.meta.status !== 200) return this.$message.error('获取商品分类数据失败')
//console.log(res.data) 测试
this.cateList = res.data.result//将商品分类数据赋值给cateList
this.total = res.data.total//为总数据条数赋值
},
},
}
</script>
<style lang="less" scoped>
</style>