Skip to content

全局过滤器:

js
Vue.filter('filterName', function (value) {
  ...
})

局部过滤器(优先级比全局过滤器更高):

js
filters: {
  filterName (value) {
    ...
  }
}

可以使用在双花括号插值v-bind 表达式:

html
<!-- 在双花括号中 -->
{{ message | filterName }}

<!-- 在 `v-bind` 中 -->
<div v-bind:id="rawId | formatId"></div>

过滤器可以串联:

html
{{ message | filterA | filterB }}

过滤器可以接收参数:

html
{{ message | filterA(arg1, arg2) | filterB }}