How to use vue mixin in this situation?

212 Views Asked by At

I have the following code in two vue component:

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

How can I use this in mixin?

this is my 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;

But I can't use it

1

There are 1 best solutions below

1
On BEST ANSWER
import EventBus from "@/eventBus";

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

export default toggle;