Vue——全局时间戳过滤器

Vue中,你可以在一个组件的选项中定义本地的过滤器,或者在创建 Vue 实例之前全局定义过滤器,在一个项目中,你可能会用到很多次的时间戳过滤器,如果在每个组件里面写就有点麻烦,下面介绍一下全局时间戳过滤器:

=================================================================
在main.js里面添加全局过滤器

Vue.filter('过滤器名称',function (传入参数) {
    
     
	   const date=new Date(createdate); 
	   const year=date.getFullYear();  
	   const month=date.getMonth()+1;
	   const day=date.getDay();    
	   const shi=date.getHours()  
	   const fen=date.getMinutes() 
	   const miao=date.getSeconds() 
	   return year+"-"+month+"-"+day+"-"+shi+"-"+fen+"-"+miao;}
 )
	

使用方法,以elementui举例

<el-table-column  label="添加时间" align="center" >   
    <template slot-scope="scope">   
     <p>{
    
    {
    
    scope.row.notificationTime | 过滤器名称(scope.row.notificationTime)</p>
    </template>
 </el-table-column>

猜你喜欢

转载自blog.csdn.net/qq_40788898/article/details/107010260