Vue2中的过滤器在Vue3中已经被移除,我们可以通过全局属性的方式来实现过滤器的相关功能
- 安装时间过滤插件mount,或者自己写一个过滤函数也可
npm install moment --save
2.在main.js中写入如下代码
import moment from 'moment'
const app = createApp(App)
app.config.globalProperties.$filters = {
timeFormat(value: string, formatString: string) {
formatString = formatString || 'YYYY-MM-DD hh:mm:ss';
return moment(value).format(formatString);
}
}
3.在需要引入的页面中使用
<template>
<el-table class="el-table" :data="tableData">
<el-table-column prop="createTime" height=&