1、由于sort-method在Table-column Attributes中,所以应使用:sort-method而不是@sort-method,且必须添加sortable属性
<el-table-column sortable label="客单价(元)" :sort-method="sortByPrice" min-width="100" align="center">
<template slot-scope="scope">
<span v-if="scope.row.collection_amount!==0">{{ (scope.row.collection_amount/scope.row.collection_num)/100 ' moneyFilter }}
</span>
<span v-else>0.00</span>
</template>
</el-table-column>
**2、判断大小并返回
踩坑:返回值应为数值,而不是boolean
// 根据客单价排序
sortByPrice(row, row1) {
if (row.collection_amount === 0) {
return -1
}
if ((row.collection_amount / row.collection_num) < (row1.collection_amount / row1.collection_num)) {
return -1
} else {
return 1
}
}