Vue3 access component data attribute from console
Asked Answered
S

1

7

How do I access a component data attribute value from the console in Vue 3?

When I was working in vue2 I was accessing this using $vm0 and setting and getting any component attribute value but this does not work in Vue 3.

Vue.js devtools screenshot with data:

enter image description here

Here I want to access isCalendarAttached from Chrome console but I am not able to:

enter image description here

Here is my app object which is the root component:

enter image description here

Is there any way I can access that variable from console?

Schilt answered 21/4, 2021 at 10:21 Comment(0)
C
9

As of Vue.js devtools v6.0.0+:

$vm0.ctx.isCalendarAttached // Read-only
$vm0.ctx.$data.isCalendarAttached // Read/Write

Or if your state is moved into setup per Composition API:

$vm0.setupState.isCalendarAttached

Note:

  1. Vue.js devtools v5 does not support Vue 3 so v6 is required.
  2. You'll still need to ensure you've first selected your Vue component in the devtools.
Cameroun answered 26/8, 2021 at 7:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.