简体   繁体   中英

How to get the component's key in Vue 3 composition setup() api?

In the regular API I can get the key like this:

created()
{
    console.log(this._.vnode.key);
}

But in the composition API, in setup(), 'this' is undefined. I tried to check the data and context properties, but can't find anything.

Figured it out:

import { getCurrentInstance } from "vue";

setup() {
    const component = getCurrentInstance();
    console.log(component.vnode.key);
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM