Vue.js 的 filter
是一种特殊的功能,允许你在mustache插值 ({
{ }}
) 或 v-bind
表达式中预处理文本。然而,需要注意的是,从 Vue 2.x 开始,filter
已被标记为废弃,并且在 Vue 3.x 中已完全移除。尽管如此,了解 filter
的工作原理和用法对于理解 Vue 的某些历史和概念仍然是有帮助的。
Vue 2.x 中的 filter
在 Vue 2.x 中,你可以使用 Vue.filter()
方法来注册全局过滤器,或使用 Vue
实例的 filters
选项来注册局部过滤器。
全局过滤器
Vue.filter('myFilter', function(