HTML
<script src="//unpkg.com/vue/dist/vue.js"></script> <script src="//unpkg.com/element-ui@2.4.0/lib/index.js"></script> <div id="app"> <template> <el-table ref="table" :data="tableData"> <el-table-column type="selection"></el-table-column> <el-table-column label="日期" prop="date"></el-table-column> <el-table-column label="姓名" prop="name"></el-table-column> <el-table-column label="操作"> <template slot-scope="props"> <el-button type="primary" @click="handleCheck(props.row)">查看</el-button> </template> </el-table-column> <el-table-column type="expand"> <template slot-scope="props"> <div>这里是详情内容</div> </template> </el-table-column> </el-table> </template> </div>
CSS
@import url("//unpkg.com/element-ui@2.4.0/lib/theme-chalk/index.css"); .el-table__expand-column .cell { display: none; }
JS
var Main = { data() { return { tableData: [ { date: '2016-05-03', name: '王小虎', province: '上海', city: '普陀区', address: '上海市普陀区金沙江路 1518 弄', zip: 200333 }, { date: '2016-05-02', name: '王小虎', province: '上海', city: '普陀区', address: '上海市普陀区金沙江路 1518 弄', zip: 200333 } ] } }, methods: { handleCheck(row) { const $table = this.$refs.table $table.toggleRowExpansion(row) $table.toggleRowSelection(row) } } } var Ctor = Vue.extend(Main) new Ctor().$mount('#app')