Vue: New v-bind:class doesn't support filters?

Created on 22 Sep 2015  ·  4Comments  ·  Source: vuejs/vue

<el v-bind:class="{ 'className': prop | filter }"></el>
filter: function(val) {
    return true;
}

it works in 0.12.15. Not working in 1.0.0-beta.1

Most helpful comment

I will add, that you can use methods v-bind:class="{ className: myMethod(prop) }" to achieve something similar to the desired syntax.

All 4 comments

I'm pretty sure that was never meant to work this way. What's the point in filtering a boolean?

All directives in 1.0 takes a single JavaScript expression. So { className: prop } is an object literal - you cannot use the filter syntax inside JavaScript expressions. You can only add filters at the end of the while directive:

<el v-bind:class="{ className: prop } | filter"></el>

So the filter would need to process the object instead of a string.

Also, it's recommended to use computed properties when a binding value gets complicated.

I will add, that you can use methods v-bind:class="{ className: myMethod(prop) }" to achieve something similar to the desired syntax.

I had to use $forceUpdate() for the bindings to apply during runtime

Was this page helpful?
0 / 5 - 0 ratings