vue filter filters ()

vue.js allows you to customize the filter, the filter can be used in two places: 双花括号插值and v-bind 表达式

html code

<div class="text-box">
  {{declaredate|formatDate}}
</div>
或者
<div v-model="
{{declaredate|formatDate}}"></div>

vue.js Code

new Vue({
                el: "#app",
                data: {
            declaredate:null
                },
                filters: {
                    formatDate(time) {
                        if(time != null) {
                            return new Date(time.replace(/-/g, "/")).format("yyyy-MM-dd");
                        } else {
                            return '无';
                        }
                    }
                }
            });
the formatDate (time) is equal to the time in the data in the declaredate used to do it is determined if the time declaredate equals null, then returns the generated new Date

Guess you like

Origin www.cnblogs.com/xieyanhui/p/11012651.html