Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get v-id-xx value for scoped css on Vue Single File Component

When adding elements via pure js on Vue Single File Component, the added elements don't have v-id-xx attribute for scoped css.

How can I get THE component's v-id-hash value by pure js?

like image 442
yokoiwa Avatar asked Dec 23 '22 08:12

yokoiwa


1 Answers

The scoped-style data ID is added to the component instance as:

this.$options._scopeId // returns something like 'data-v-763db97b'

This way you could add it as attribute using:

somElement.setAttribute(this.$options._scopeId, "");

Here's a CodeSandbox demo showing an example.

like image 188
acdcjunior Avatar answered Jan 13 '23 13:01

acdcjunior