[Vuejs]-VueJS: apply mixin to async component

0๐Ÿ‘

I found some creepy(?) solution, but it works:

// mixins.js
export default class Mixins {
   static fooMixin() {
     return {
       created: function () {
         console.log('mixin hook called');
       }
     }
   }
}

// app.js
Vue.component("foo", resolve => {
  require(['./components/foo.vue'], resolve);
});

// foo.vue
<script>
  import Mixins from "mixins";

  export default {
    ...
    mixins: [Mixins.fooMixin()]
  }
</script>

But I hope that there is a more elegant solution.

๐Ÿ‘คNikitaK

Leave a comment