Vue: Allow to use filter in conditional expression

Created on 15 Apr 2017  路  2Comments  路  Source: vuejs/vue

What problem does this feature solve?

i am submitting this as a feature rather than a bug because I can't find any mention of why it isn't supported (maybe you have a reason) or similar bug report.

So.. currently, I can't use filters inside conditional statement, like this:

{{ prop !== null ? (prop | myFilter) : 'no data' }}

i can however use method instead of filter:

{{ prop !== null ? myFilter(prorp) : 'no data' }}

well I can also handle null value in my filter and I get my data filtered, but why not support it also in ternary expression? :)

Example: https://jsfiddle.net/Ljressro/

Thanks <3

What does the proposed API look like?

API wouldn't change.

Most helpful comment

The expression syntax is defined as (JavaScript expression) + (| filters). Filters can only be appended to valid JavaScript - bringing in filters into JavaScript is not going to happen.

You can already use $options.filters.myFilter(prop) in JavaScript expressions.

All 2 comments

The expression syntax is defined as (JavaScript expression) + (| filters). Filters can only be appended to valid JavaScript - bringing in filters into JavaScript is not going to happen.

You can already use $options.filters.myFilter(prop) in JavaScript expressions.

Thanks @yyx990803
I'll suggest to add this in docs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

julianxhokaxhiu picture julianxhokaxhiu  路  3Comments

hiendv picture hiendv  路  3Comments

wufeng87 picture wufeng87  路  3Comments

robertleeplummerjr picture robertleeplummerjr  路  3Comments

loki0609 picture loki0609  路  3Comments