场景:项目中难免会遇到一些要处理的数据啥的,又不能遇到一个写一个,最好是能一键使用
代码:
新建文件夹 global / index.ts
import type { App } from 'vue'
function registerGlobalProperties(app: App) {
app.config.globalProperties.$filters = {
showStatus(enable: boolean) {
return enable ? '启用' : '禁用'
},
其他方法
}
app.config.globalProperties.form
}
export default registerGlobalProperties
注册
....
import { globalRegister } from '@/global/register'
const app = createApp(App)
globalRegister(app)
....
使用
在你需要处理数据的地方,这样写即可
{{ $filters.showStatus(你要处理的值) }}