定义全局时间过滤器

<template>
<div>
<h3>格式化时间</h3>
<p>{{time|timeFormat}}</p>
<p>{{time|timeFormat("YYYY")}}</p>

</div>
</template>
<script>

export default{
    name:"foemt",
    data(){
        return {
        time:new Date(),
        }
    },
    mounted(){
        setInterval(()=>{
            this.time=new Date()
        },1000);
    },
}
</script>
<style scoped>
</style>

  注意:要若是没安装插件记得在项目安装插件:npm i moment --savehtml

Vue.filter('timeFormat',(value,format='YYYY-MM-DD HH:mm:ss')=>{
  return moment(value).format(format);
});
相关文章
相关标签/搜索