I'm struggling to understand the extent to which Vue 3 composition API methods can access the attributes of a Vue app, including data
.
Check out this jsfiddle, which is based on a fork of the Vue demo fiddle.
With a method defined in the options API, it's easy to retrieve values from data
.
However, when using a method defined in the composition API, it seems like data
and the app instance are out of reach. There's no this
, as previously mentioned. It feels like the composition and options API parts are isolated from each other.
testopt
, defined in the options API, has access to data
and references returned by setup
.
"Yo! from options API: Hello Vue!"
"this.msg2: Hello2"
testcompo
, defined in the composition API, cannot see data
, but can see references returned by setup.
"Yo! from composition API: this: undefined:"
"context: [object Object]: "
"context.data: undefined:"
"context.$data: undefined:"
"context.attrs: [object Object]: "
"context.attrs.data: undefined:"
"arg2: undefined:"
"msg2: Hello2"
"Yes, I know how setup and refs work. counter is now: 4"