I created a basic custom filter for my vue.js app which I intend to use extensively for y API variables. This is the filter in my app.js file:
filters: {
myFilter: function(val) {
return val.toFixed(0)
}
},
In my index.html I simply call it like this
<p> {{ foo.bar.num | myFilter }} </p>
This returns an error. Cannot read property 'toFixed' of undefined
. The problem is foo.bar.num
is not defined until the API is loaded. The API has so many variables I want to use for my custom filter that it would be impractical to pre-define them all in the data option.
What would be the best approach in this case?