How to reuse same function in more than one vue component

994 views Asked by At

I have onClick handler in 6 vue components that is repeated, I extracted it in this mixin

//mixin.vue
export default {
  methods: {
  onLastMonth () {
    // get first day of the month.
    // get last day of the month
    // call axios GET method.
  }
}

//component.vue
import mixin1 from './components/mixin.vue'
export default {
  mixins: [mixin1],
  name: 'component1'
}

I want to reuse that mixin in other 6 vue components but the onClick event fired this error in the browser console:

Property or method "onLastMonth" is not defined on the instance but referenced during render.

0

There are 0 answers