由于項目的需求規(guī)定表格中的內(nèi)容超出部分不能懸浮顯示,要自適應(yīng)寬,先element 表格的是不支持自適應(yīng)的癞松,經(jīng)過搜索引用了基于 Element-UI 二次封裝的支持自適應(yīng)列寬的 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>
<!--也支持簡單的自定義內(nèi)容-->
<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>