vuex filter过滤器用法

格式化日期

Vue.filter('formatDate', (time) => {
    let date = new Date(time * 1000);
    let Y = date.getFullYear();
    let M = date.getMonth() + 1;
    let D = date.getDate();
    let h = date.getHours();
    let m = date.getMinutes();
    let s = date.getSeconds();
    return `${Y}-${M}-${D} ${h}:${m}:${s}`;
})

vue 页面

{{time|formatDate}}

处理字符串

Vue.filter('joinActors', arr => {
    const list = JSON.parse(arr)
    const actors = list.map(item => {
        return item.name;
    });
    const str = actors.join(' ');
    return str;
})

你可能感兴趣的:(vuex filter过滤器用法)