The element-UI component library is used in the project. Here, common operations are briefly sorted out. If there are similar functions, you can make a reference

For specific methods, please read the section of Table on the official website:

The document

The table – the column – scoped – slot document

Customize the contents of the column


Requirement: Add action buttons

Add action button via slot-scope=”scope”, this is the slot provided specially for us, easy to customize different content.

<el-table-column> <template slot-scope="scope"> <el-button size="mini" type="primary"> Edit </el-button> <el-button Size ="mini" type="danger"> delete </el-button> </template> </el-table-column>Copy the code

Scope.$index Gets the current row index

The added action button can use scope.$index to retrieve the subscript of the current row

<el-table-column label="操作" width="160">
	<template slot-scope="scope">
		<el-button size="mini" type="primary" plain @click = "showIndex(scope.$index)">点击显示当前行下标</el-button>
	</template>
</el-table-column>
Copy the code

Scope. row gets the current property value

The scope.row. Property name is used to obtain the property value for the current row

<el-table-column label=" operation "width="160"> <template slot-scope="scope"> <el-button size="mini" type="primary" plain @click = "showName(scope.row.name)"> </el-button> </template> </el-table-column>Copy the code

Special attribute values can be styled using scope.row. Attribute names and ternary operators

<el-table-column prop="name" :label="langConfig.table.name[lang]" width="200"> <template slot-scope="scope"> <div : scope. Row. Class = "name = = = 'da-hu wang'? 'styleColor:"' "> {{scope. Row. The name}} < / div > < / template > < / el - table - column >Copy the code

Write a styleColor style and set the font color

.styleColor{
    color:red;
 }
Copy the code

Set the style


header-cell-class-name(Thead)

A callback method for className of header cells. You can also set a fixed className for all header cells using a string. Function form: Passes the headerStyle method to header-cell-class-name

<el-table :data="tableData" class="table" stripe // zebra border // border :header-cell-class-name="headerStyle" // Set style >Copy the code

Write headerStyle, return class name tableStyle

headerStyle ({row, column, rowIndex, ColumnIndex}) {return 'tableStyle'} --------------- // Set style <style>. TableStyle {background:#F5F7FA; font-weight:400; } </style>Copy the code

header-cell-style(Thead)

Header cell style callback method, can also use a fixed Object to set the same style for all header cells. Function form: Pass the tableHeaderStyle method to header-cell-style

<el-table 
	:data="tableData[lang]" 
	class="table" 
	stripe 
	border 
	:header-cell-style='tableHeaderStyle'
>
Copy the code

Write the tableHeaderStyle method to return the style

tableHeaderStyle ({row, column, rowIndex, columnIndex}) { return 'background-color:#1989fa; color:#fff; font-weight:400; '}Copy the code