function returnTwo(t) { return ('0'+t).toString().slice(-2); } Vue.filter('filterTime',function (value) { var t = new Date(value).getTime(); var time = new Date(t); var Y = time.getFullYear(); var M = returnTwo(time.getMonth()); var D = returnTwo(time.getDate()); var HH = returnTwo(time.getHours()); var MM = returnTwo(time.getMinutes()); var SS = returnTwo(time.getSeconds()); return `${Y}-${M}-${D} ${HH}:${MM}:${SS}` })
定义一个全局过滤器即可使用;