Vue

element-ui table表格列宽自动适应

2019-04-19  本文已影响0人  重启试试吧
由于项目的需求规定表格中的内容超出部分不能悬浮显示,要自适应宽,先element 表格的是不支持自适应的,经过搜索引用了基于 Element-UI 二次封装的支持自适应列宽的 table-column 列组件github link af-table-column

安装

npm install af-table-column

在main.js引入

import Vue from 'vue'
import ElementUI from 'element-ui'
//需要按需引入,先引入vue并引入element-ui
import AFTableColumn from 'af-table-column'
Vue.use(AFTableColumn)

组件中使用方法

<template>
  <el-table :data="data">
    <af-table-column label="列1" prop="field1"></af-table-column>
    <af-table-column label="列2" prop="field2"></af-table-column>
    
    <!--也支持简单的自定义内容-->
    <af-table-column label="列3">
      <template slot-scope="scope">
        <div>自定义显示值31: {{ scope.row.field31 }}</div>
        <div>自定义显示值32: {{ scope.row.field32 }}</div>
      </template>
    </af-table-column>
  //也支持element-ui原有的el-table-column
    <el-table-column  label="操作">
      <template slot-scope="scope">
        <el-button @click="removeItem">删除</el-button>
      </template>
    </el-table-column >
    //af-table-column 和af-table-column 可以同时在一个表格中使用
  </el-table>
</template>
上一篇 下一篇

猜你喜欢

热点阅读