Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kachi_dk's avatar

Can you use compostables in options api

I'm trying to migrate a React project to Vue, I'm tired of React the DX is really bad. I like the options api, it forces people to organize code. I have lots of hooks in the React project and I want to convert them to compostables and use them in options API. If possible please use an example, God bless

0 likes
1 reply
drehimself's avatar

Yeah it should work: https://vuejs.org/guide/reusability/composables.html#using-composables-in-options-api

I was actually curious if it could work without the setup method as well. This worked for me (you can see the code for useMouse in the docs posted above):

<template>
  <div>
    Mouse position is at: {{ x }}, {{ y }}
  </div>
</template>

<script>
import { useMouse } from "../composables/useMouse"

export default {
  data() {
    return {
      x: useMouse().x,
      y: useMouse().y,
    }
  }
}
</script>

Please or to participate in this conversation.