在我们传输参数的时候,需要对参数临时做处理,可以封装一个个小Filter进行处理
timeFilter(mill) {
return new Date(mill).toDateString().format('yyyy-MM-dd HH-mm-ss')
},
textFilter(text) {
console.log('文档过滤器进入')
if (text.size() <= 20) return text
return text.substring(0, 20)
}
类似这种;
在tag标签使用时,需要在标签属性中使用过滤器,我们可以把方法放在
这里调用
export default {
isReadTagTypeFilter(isRead) {
return { '0': 'danger', '1': 'success' }[isRead]
}
}
使用的时候我们可以将类型动态绑定这个参数,使用常规的type=“”太麻烦了
<el-table-column label="isRead" width="110px" align="center">
<template slot-scope="{row}">
<el-tag :type="row.isRead | isReadTagTypeFilter">{{ {'0':'unRead','1':'isRead'}[row.isRead] }}</el-tag>
</template>
</el-table-column>
内容方面的过滤器由于只有两个选项我就不封装方法了
土法时间格式化
timeFilter(mill) {
const date = new Date(mill)
const year = date.getFullYear()
const month = date.getMonth()
const day = date.getDay()
const hours = date.getHours()
const minutes = date.getMinutes()
const seconds = date.getSeconds()
return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
}