vue日期格式化
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title></title> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script> <script src="https://unpkg.com/axios/dist/axios.min.js"></script> </head> <body> <div id='app'> {{time | timeFormat('YYYY-MM-DD hh:mm:ss')}} </div> <script> Vue.filter('timeFormat', function (data, format) { let Y = data.getFullYear(); let M = (data.getMonth() + 1).toString().padStart(2, 0); let D = (data.getDate()).toString().padStart(2, 0); let h = (data.getHours()).toString().padStart(2, 0); let m = (data.getMinutes()).toString().padStart(2, 0); let s = (data.getSeconds()).toString().padStart(2, 0); return format.replace("YYYY", Y).replace("MM", M).replace("DD", D).replace("hh", h).replace("mm", m).replace("ss", s); }) const vm = new Vue({ el: '#app', data: { time: new Date() }, methods: { }, }) </script> </body> </html>