Replies: 5 comments 3 replies
-
I think it would increase performance overhead. Since naive use id to check if component style exists. If every element has it's scope style, i think this may be a large overhead? |
Beta Was this translation helpful? Give feedback.
-
Well it doesn't have to be in each component. The logic is more or less the same as of now but it would not be the in the document.head.
And to solve the problem I do the following in onMounted:
So the style is not included in every button but only once in the whole component. The idea would be to specify where the style tag is included in useTheme.
If nodeToInsertIn is null then I use document.head. But I could pass for example selfEl.getRootNode() for a custom element and the |
Beta Was this translation helpful? Give feedback.
-
I have a similar problem when I try mounting a vue app inside an iframe. Has there been a solution for this? Thank you! |
Beta Was this translation helpful? Give feedback.
-
@jbmolle @07akioni It might cause issue if the naive UI version is conflicting in the consumer application. Let say an application consumes a web component which internally using naive UI. Also the consumer application uses naive UI but with different version. This might cause problem if different version of naive UI has different css style. what's your thoughts in this ? |
Beta Was this translation helpful? Give feedback.
-
使用最新版本(2.38.1),配合 vue 的 defineCustomElement 基于 SFC 构建 WebComponents,样式丢失,请问有什么解决方案吗? |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm trying to create a custom element from a Vue component with Vue 3 function defineCustomElement.
Let say the component is just a NaiveUI Button.
The problem is that in a Vue app NButton works perfectly but in a custom element there is no CSS style applied.
Actually NButton uses
useTheme
which renders the CSS classes with css-render.useTheme
usesstyle.mount
which callsdocument.head.appendChild
ordocument.head.insertBefore
. So we get inline stylesheets in the head of the page. The problem with Vue3 custom elements is that a shadow root is automatically inserted and so everything inside the custom element doesn't have access to the stylesheets in head.Would it be possible to add a custom variable to mount.ts with the dom element where the style should be inserted. So per default it would include to document.head but if we give a specific element, it would insert it in a style tag in the shadow root.
Let me know what you think and if you see another solution.
Thanks,
JB
Beta Was this translation helpful? Give feedback.
All reactions