在这种情况下如何使用vue mixin?

How to use vue mixin in this situation?

我在两个 vue 组件中有以下代码:

  data() {
    return {
      overlay: false
    };
  },
  created() {
    EventBus.$on("toggleSidebar", status => (this.overlay = status));
  }

如何在 mixin 中使用它?

这是我的混音 (toggle.js)

import EventBus from "@/eventBus";

const toggle = () => {
  return {
    data() {
      return {
        show: false
      };
    },
    created() {
      EventBus.$on("toggleSidebar", status => (this.show = status));
    }
  };
};

export default toggle;

但是我不会用

import EventBus from "@/eventBus";

const toggle = {
  data() {
    return {
      show: false
    };
  },
  created() {
    EventBus.$on("toggleSidebar", status => (this.show = status));
  }
};

export default toggle;