[Vuejs]-Vue how to call filter from parent

0👍

There is no point. Just include your mixin in the child as well. A component should ideally be autonomous, and not aware of where it is in the hierarchy of components (at least not the ones above or on the same level.

5👍

  • You should just make the filter global available before starting the root instance with

    Vue.filter('uppercase', uppercase);
    

    Where uppercase can be a simple function like

    function uppercase(str)
      return str.uppercase();
    }
    

    That would be the most simple and reliable way to use the filter on all vue components;

  • If you import your filters to your parent via mixins why don’t you use that mixin in the child?

  • Please do not use the this.$parent-method as it makes your child component statical dependend of that parent.

    • To use the $parent approach you may need to declare the filter function from the parent as a filter in the child:

      filters:{
      uppercase: this.$parent.$options.filters.uppercase
      }

👤Reiner

Leave a comment