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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.