Vuejs 3: how to use mixins in class component?

Viewed 776

I started migrating my app from vue 2 to vue 3 and in my project I use class components. I didn't find way how can I use mixins in Vuejs 3. Is it possible and how to use mixins in vuejs 3?

current code: export default class HomePage extends Mixins(Vue, PageMixin) {}

2 Answers

I know it is not a direct answer to your question but as stated here https://vuejs.org/api/options-composition.html#mixins

In Vue 2, mixins were the primary mechanism for creating reusable chunks of component logic. While mixins continue to be supported in Vue 3, Composition API is now the preferred approach for code reuse between components.

It is same with the Vue2

const mixin = {
  created() {
    console.log(1)
  }
}

Here you can use it:

createApp({
  mixins: [mixin],
  created() {
    console.log("test")
  },
})
Related