vue_过滤器: 对要显示的数据进行特定格式化后再显示

过滤器

对要显示的数据进行特定格式化后再显示

并未改变原本的数据,可是产生新的对应的数据

  • <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="UTF-8">
            <title>10_Vue_filter</title>
            <link rel="stylesheet" type="text/css" href="./css/index.css">
        </head>
        <body>
            <div id="test">
                <p>{{curTime | timeFormat}}</p>
            </div>
            <script src="https://cdn.bootcss.com/moment.js/2.24.0/moment.js"></script>
            <script src="./js/vue.js"></script>
            <script>
                Vue.filter("timeFormat", function (value, timeType="YYYY-MM-DD HH:mm:ss") {
                    let newValue = moment(value).format(timeType);
                    return (newValue === "Invalid date")?"":newValue;
                });
                new Vue({
                    el: "#test",
                    data:{
                        curTime: ""
                    },
                    mounted(){
                        setInterval(()=>{
                            this.curTime = Date.now();
                        }, 1000)
                    }
                });
            </script>
        </body>
    </html>

 

--------小尾巴 ________一个人欣赏-最后一朵颜色的消逝-忠诚于我的是·一颗叫做野的心.决不受人奴役.怒火中生的那一刻·终将结束...
原文地址:https://www.cnblogs.com/tianxiaxuange/p/10386839.html