2
I know to use a filter on Vue
, you can make the call as follows:
Vue.filter('hello', function (input) {
return "hello, " + input;
})
new Vue({
el: "#app",
data: {
name: "Wallace",
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.min.js"></script>
<div id="app">
{{ name | hello }}
</div>
That is, through interpolation, it is possible to call a filter
perfectly.
The problem is when I try to use the v-text
. It seems that Vue behaves differently in these cases.
Vue.filter('hello', function (input) {
return "hello, " + input;
})
new Vue({
el: "#app",
data: {
name: "Wallace",
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.min.js"></script>
<div id="app">
<span v-text="name | hello"></span>
</div>
Note that when running, an error appears:
hello
is not defined
In this case, I come from Angularjs and know that it is possible to use the filters
so much with ng-bind
as with interpolation.
But in the case of Vue
? Why doesn’t it work?
I saw no detail in the documentation regarding this.
Is there any way to circumvent this problem?
From Vue 1.x > 2.x migration guide: Filters Outside Text Interpolations (Removed)
– bfavaretto