如何在多个vue组件中重用同一功能

时间:2018-11-16 21:57:00

标签: vue.js vue-component vue-mixin

我在重复的6个vue组件中都有onClick处理程序,我在此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'
}

我想在其他6个vue组件中重用该mixin,但是onClick事件在浏览器控制台中引发了此错误:

属性或方法“ onLastMonth”未在实例上定义,但在渲染过程中被引用。

0 个答案:

没有答案
相关问题