<el-table
ref="table"
:data="tableData"
stripe
@sort-change="changeTableSort"
:default-sort="{ prop: 'createDate', order: 'descending' }"
>
<el-table-column
prop="createDate"
label="添加时间"
width="180"
sortable
:sort-orders="['descending', 'ascending']"
>
</el-table-column>
<el-table-column
prop="saleVolume"
label="销量"
sortable
:sort-orders="['descending', 'ascending']"
>
</el-table-column>
</el-table>
注意一下几点:
1,:default-sort="{ prop: 'createDate', order: 'descending' }"
2,:sort-orders="['descending', 'ascending']"
3,sortable
this.pages.volumeSort 和 this.pages.sort 是我需要传给后台的参数 ,可自行自定义
changeTableSort ({ column, prop, order }) {
if(prop==='saleVolume'){
this.pages.volumeSort = column.order === 'descending' ? 'DESC' : 'ASC'
}else{
this.pages.sort = column.order === 'descending' ? 'DESC' : 'ASC'
}
},