Say I have a Vue instance like so:
new Vue({
el: '#app',
data: {
word: 'foo',
},
filters: {
capitalize: function(text) {
return text.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
}
},
methods: {
sendData: function() {
var payload = this.$filters.capitalize(this.word); // how?
}
}
}
I can easily use the filter in a template like so:
<span>The word is {{ word | capitalize }}</span>
But how can I use this filter from within an instance method or computed property? (Obviously this example is trivial and my actual filters are more complex).
This is what worked for me
Defining filter
Using filter
See http://vuejs.org/api/#vm-options
To complement Morris answer, this is an example of a file I normally use to put filters inside, you can use in any view using this method.