Vue 3 brakes when using Options API in conjunction with setup script and vite build
Version
3.2.31
Reproduction link
Steps to reproduce
I like to use a combination of the script setup with the options API, and I have encountered a strange issue that has never before happened to me and I've managed to create a new environment to replicate the issue here:
https://stackblitz.com/edit/vitejs-vite-3sc8ha
The file to look at is the App.vue
So basically what happens is that the computed property named "theme" is undefined since the testStore is undefined inside the options API theme getter.
*Important note: It only fails when using "vite build" and it does not happen when using "vite"
If I remove the options API defineComponent script and create the computed property in the setup script as so:
const theme = computed(() => {
return store.getTheme;
});
To summarize the issue:
The defineExpose doesen't seem to be working well when building the vue app for production.
Is this approach of having 2 scripts wrong because I have been working like this since I started using Vue 3 and I haven't had any issues with this until recently.
What is expected?
Expected to work when building the app
What is actually happening?
Only working when in dev mode with "vite" command.
This may be a Vite issue so I am not sure.
- regular script should always go before the setup one
- Do not mix composition and options api styles within the same component
@posva The documentation says it is possible to mix both APIs within the same component.
@truefusion only for things that cannot be done with composition api, like the ones mentioned in docs, in other words: that isn't mixing composition api and options api, it's adding component options
Then perhaps the documentation should be altered to warn of the implications because it is not made clear that i am only to use 2 scripts if i need the component name.
@posva it is a pain that this is working in dev environment but not in the build. Should definitly not working in dev, then.