I've got a strange problem: I'm unable to access data() from a vue instance:
const vueapp = Vue.createApp({
data(){
return {
form:{ .... }
[etc..]
// later:
console.log(vueapp.$data, vueapp.form) // both undefined
Why?
https://v3.vuejs.org/guide/instance.html#creating-an-application-instance
The app and its root component are subtly but importantly different. The options you pass to createApp
don't exist on the app, but its root component.
The options passed to createApp are used to configure the root component. That component is used as the starting point for rendering when we mount the application.
const app = Vue.createApp(RootComponent) const vm = app.mount('#app')
You can do vm.$data
and vm.form
in the above code sample, but not app.$data
or app.form
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With