Vue中filters过滤时间的用法(一看就会)

在这里插入图片描述

<template>
	<view>
		发表时间:{{item.add_time | formatDate}}
	</view>
</template>

<script>
	export default{
		filters:{
			formatDate(date){
				const nDate=new Date(date)
				//将不满10的数字自动补0
				const year=nDate.getFullYear().toString().padStart(2,0)
				const month=nDate.getMonth()
				const day=nDate.getDay().toString().padStart(2,0)
				return year+'-'+month+'-'+day
			}
		}
	}
</script>

<style>
</style>

猜你喜欢

转载自blog.csdn.net/hong521520/article/details/106921990
今日推荐