useAttrs().style and useAttrs().class - How to bind attrs.style and attrs.class to external HTMLDivElement instance?
#14555
Unanswered
rtcpw
asked this question in
Help/Questions
Replies: 1 comment 1 reply
-
|
@rtcpw Nice integration scenario. Since that div is created outside Vue template rendering, fallthrough attrs (class / style) are not auto-applied there. Practical approach:
That keeps Vue as source-of-truth while still supporting third-party DOM ownership. References: |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have created a native div element:
I need to create an element like this because of the third-party mapping library that I use.
I would like to use Vue's
:classand:stylebinding to bind the class/style to this element. To achieve this, I have wrapped thedivelement above in a custom component, and useduseAttrstogether withdefineOptionsto grab the attributes:The
attrs.styleis of typeStyleValue, andattrs.classis of typeClassValue:I have not found a way to easily take
attrs.classandattrs.styleand bind it to thediv(HTMLDivElement) above. Is there any utility function or perhaps some other approach I could take to achieve this?Alternatively, is there a utility function that would convert these rather complex types (which are not the easiest to work with manually), and turn them into something easier to digest, eg. a simple
Record<string, string>in the case ofattrs.style, and perhapsSet<string>in case ofattrs.class? This would at least give me the option to loop over these objects and calldiv.style.setPropertymyself.Beta Was this translation helpful? Give feedback.
All reactions