add filters

This commit is contained in:
zhl 2021-01-20 16:47:44 +08:00
parent 455d5ed520
commit b6594cdf3b
2 changed files with 22 additions and 0 deletions

17
src/filters/index.ts Normal file
View File

@ -0,0 +1,17 @@
// Set utils function parseTime to filter
export { parseTime } from '@/utils'
// Filter for article status
export const articleStatusFilter = (status: string) => {
const statusMap: { [key: string]: string } = {
published: 'success',
draft: 'info',
deleted: 'danger'
}
return statusMap[status]
}
// Filter to uppercase the first character
export const uppercaseFirstChar = (str: string) => {
return str.charAt(0).toUpperCase() + str.slice(1)
}

View File

@ -15,6 +15,7 @@ import '@/icons/components'
import '@/permission' import '@/permission'
import { AppModule } from '@/store/modules/app' import { AppModule } from '@/store/modules/app'
import * as directives from '@/directives' import * as directives from '@/directives'
import * as filters from '@/filters'
Vue.use(ElementUI, { Vue.use(ElementUI, {
size: AppModule.size, size: AppModule.size,
@ -29,6 +30,10 @@ Vue.use(SvgIcon, {
Object.keys(directives).forEach(key => { Object.keys(directives).forEach(key => {
Vue.directive(key, (directives as { [key: string ]: DirectiveOptions })[key]) Vue.directive(key, (directives as { [key: string ]: DirectiveOptions })[key])
}) })
// Register global filter functions
Object.keys(filters).forEach(key => {
Vue.filter(key, (filters as { [key: string ]: Function })[key])
})
// Register global directives // Register global directives
Vue.config.productionTip = false Vue.config.productionTip = false