antDesignPro a-table样式二次封装

1 篇文章 0 订阅

antDesignPro是跟element-ui类似的一个样式框架,其本身就是一个完整的后台系统,风格样式都很统一。我使用的是antd pro vue,版本是1.7.8。公司要求使用这个框架,但是UI又有自己的一套设计。这就导致我需要对部分组件进行一定的个性化封装。
对antdesign vue的a-table进行二次封装:新建路径 components/comTable/index.vue

<script>
export default {
  name: 'com-table',
  props: {
    dataSource: Array,
    columns: Array
  },
  render () {
    const on = {
    ...this.$listeners
    }
    const props = { ...this.$attrs, ...this.$props, ...{ dataSource: this.dataSource, columns: this.columns }}
    // slots循环
    const slots = Object.keys(this.$slots).map(slot => {
      return (
        <template v-slot={slot}>{ this.$slots[slot] }</template>
      )
    })
    const table = (
      <a-table props={props} scopedSlots={ this.$scopedSlots } on={on}>
        {slots} 
      </a-table>
    )
    return (
      <div class="com-table">
        { table }
      </div>
    )
  },
};
</script>
// 下面自定义表格样式
<style lang="less" scoped>
</style>

对comTable组件进行全局注册:路径:components/globalComponents.js

// 全局组件注册
import comTable from './comTable'
const globalComponents = {
  install (Vue) {
    Vue.component('comTable', comTable)
  }
}
export default globalComponents

main.js中添加

// 公共UI组件
import globalComponents from '@/views/spmSystem/components/globalComponents'
Vue.use(globalComponents)

页面使用示例,封装的comTable使用与a-table无异,仅改变了样式,方便表格样式的统一修改。

                <com-table
                  style="margin:-10px 5px 0 5px" 
                  :dataSource="dataSource" 
                  :columns="columnsThree" 
                  size="small" 
                  :pagination=false 
                  :scroll="{ x: '100%', y:170 }"
                >
                  <span slot="a" slot-scope="text" :style="{color:(text == '重大'?'red': ( text == '较大'?'#F98C00FE':'#D7B22EFE') )}">{{ text }}</span>
                </com-table>
  • 14
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要禁用 Ant Design Vue 表格(a-table)中的特定单元格,您可以使用 `customRender` 属性来自定义单元格的渲染方式。通过在自定义渲染函数中添加逻辑,您可以控制单元格是否可编辑或禁用。 下面是一个示例,演示如何禁用特定单元格: ```vue <template> <a-table :data-source="dataSource"> <a-table-column title="Name" dataIndex="name" customRender="nameRender"></a-table-column> <a-table-column title="Age" dataIndex="age" customRender="ageRender"></a-table-column> </a-table> </template> <script> export default { data() { return { dataSource: [ { name: 'John', age: 30, editable: true }, { name: 'Jane', age: 25, editable: false }, ], }; }, methods: { nameRender(text, record, index) { return { children: <span>{{ text }}</span>, attrs: { // 根据 editable 属性来判断是否禁用单元格 disabled: !record.editable, }, }; }, ageRender(text, record, index) { return { children: <span>{{ text }}</span>, attrs: { // 根据 editable 属性来判断是否禁用单元格 disabled: !record.editable, }, }; }, }, }; </script> ``` 在上面的示例中,我们定义了一个 `dataSource` 数组,其中包含两个对象,每个对象代表一行数据。在 `nameRender` 和 `ageRender` 函数中,我们使用 `customRender` 属性来自定义单元格的渲染方式。根据 `editable` 属性的值,我们决定是否禁用单元格。 请注意,上述示例中的 `customRender` 函数使用了 Vue 的 JSX 语法。如果您不熟悉 JSX,您也可以使用普通的模板语法来实现相同的效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值