①传递一个参数
<h1>{{time | dateFormat}}</h1>
data: {
time: new Date
}
Vue.filter('dateFormat', (dateData) => { // 默认有一个形参就是要过滤的数据
return dateData.getFullYear() + '-' + (dateData.getMonth()+1) +'-' + dateData.getDate()
})
②传递两个参数
<h1>{{time | dateFormat('/')}}</h1>
data: {
time: new Date
}
Vue.filter('dateFormat', (dateData, fuhao = '-') => { // 默认有一个形参就是要过滤的数据
return dateData.getFullYear()+fuhao+(dateData.getMonth()+1) +fuhao + dateData.getDate()
})