1. // 在vue中的main.js 中添加过滤器
    2. // 在src/main.js
    3. import * as filters from './filters';
    4. Object.keys(filters).forEach(key => Vue.filter(key, filters[key]))
    5. // 在src/filters/index.js
    6. export function formatDate(str) {
    7. if (str) {
    8. let date = new Date(str);
    9. let year = date.getFullYear(),
    10. month = String(date.getMonth() + 1).padStart(2, '0'),
    11. day = String(date.getDay()).padStart(2, '0'),
    12. hour = String(date.getHours()).padStart(2, '0'),
    13. minute = String(date.getMinutes()).padStart(2, '0'),
    14. second = String(date.getSeconds()).padStart(2, '0');
    15. return `${year}-${month}-${day} ${hour}:${minute}:${second}`
    16. }
    17. }
    18. // 想要过滤哪里的数据就写在哪里 三种写法
    19. <div class="time">
    20. {{ detailList.createAt | formatDate }}
    21. </div>