element UI-table表格列宽自适应

1.element UI关于表格宽度的可以使用width和show-overflow-tooltip(超出部分悬浮显示)

以及列宽自适应的fit,但是这个属性不好使,也不知道为什么

2.查了一些资料,发现有用width的有自己写的(本人小白看不懂),无意中发现一个利用的,亲测有效,

具体步骤如下:

1)安装

npm install af-table-column

2)在main.js中引用

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

Vue.use(AFTableColumn)

3)在el-table中使用

<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 和el-table-column 可以同时在一个表格中使用
  </el-table>
</template>
经验分享 程序员 微信小程序 职场和发展