一个vue的过滤器本质上是一个函数,这个函数会接收一个值,将其处理并返回。过滤器在指令中有一个符(|)标记,并且跟随一个或多个参数:
<element directive="expression|filter[args...]"></element>
过滤器必须放在一个指令的值得最后:
<span v-text="message|capitalize"></span>
也可以用在mustache风格的绑定的内部:
<span>{{message|uppercase}}<span>
可以串联多个过滤器:
<span>{{message|lowercase|reverse}}</span>
参数
一些过滤器可以接受参数的。参数用空格分隔开
<span>{{order|pluralize 'st' 'nd' 'rd' 'th'}}</span> <input v-on="keyup:submitForm|key 'enter">
纯字符串参数需要用引号包裹。无引号的参数会作为表达式在当前数据作用域内动态计算。后面会进一步讨论这些细节。