Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Map global filters to local methods to use them in components as well as templates
/**
* Map global filters for being used from within `methods`. This makes them usable in js as well as templates
* @param {Array} filters - A list of registered filter names
* @return {Object) An object containing filters and their functions
*/
export function mapFilters(filters) {
return filters.reduce((result, filter) => {
result[filter] = function(...args) {
return this.$options.filters[filter](...args);
};
return result;
}, {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.