[Vuejs]-How to inherit common methods in Vue.js?

0👍

You can use the mapGetters helper to more easily import getters from your store as computed properties.

For example, in your component:

import { mapGetters } from 'vuex'

export default {
  // ...
  computed: {
    // mix the getters into computed with object spread operator
    ...mapGetters([
      'hasPermission',
      // ...
    ])
  }
}

0👍

I’d recommend using vuex, however it is possible by using provide / inject.

For example in your main app:

provide: {
    user: {
        admin: true
    }
}

And then in child components:

inject: ['user'],

created () {
    console.log(this.user);
}

Leave a comment