Specific steps:
1. Download npm i moment -S
2.main.js mount (global filters)
A plurality of components and subcomponents are used in other time, so setting the global filter main.js.
// Import formatted time widgetImport from Moment 'Moment'
// define global filter, a name
Vue.filter ( 'dataFormat', function ( dataStr, pattern = "YYYY-MM-DD HH: mm: ss ") {
// direct call moment, to get the current time
moment()
// given time, according to the object to give a moment, put the string parameter passed
moment(dataStr)
// call the format method
return Moment (dataStr) .format (pattern)
})
return Moment (dataStr) .format (pattern)
})
3. subassembly in need thereof, by adjustment to pipe character, as long as if the date, reference can be transferred
The <span> Published: {{item.add_time | dataFormat ( 'YYYY-MM-DD')}} </ span>