为什么我的Vuetify应用将其变成Web组件时会丢失其样式?

发布于 2025-01-31 03:20:05 字数 292 浏览 6 评论 0原文

我正在尝试使用Vuetify构建Web组件。但是,当我将该Web组件嵌入容器中时,Shadow-Dom失去了其样式,结果只是一堆暗淡的灰色按钮。

我创建了一个简单的示例,说明了我在说什么:

https://github.com /spierepf/vuetify-webcomponent-poc

I am trying to build a web component using vuetify. However, when I embed that web component in a container, the shadow-dom loses its styling and the result is just a bunch of dull grey buttons.

I've created a simple example of what I am talking about at:

https://github.com/spierepf/vuetify-webcomponent-poc

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生活了然无味 2025-02-07 03:20:05

当您使用其任何组件时,将CSS样式添加到文档顶部。因此,当您的组件被包裹在Shadow dom内的自定义元素中时,则在Shadow dom中无法访问veutify提供的所有样式。

您可以尝试两种选项:

  1. 使用自定义元素而无需Shadow dom
  2. 尝试使用构造样式表

Veutify add the CSS styling to the top of the document when you use any of its components. So when your component gets wrapped inside a custom element within Shadow DOM, then all the styling provided by Veutify is not accessible inside shadow DOM.

There are two options you can try:

  1. Use custom elements without shadow DOM
  2. Try to inject Veutify inside shadow DOM using constructible stylesheets.
轻拂→两袖风尘 2025-02-07 03:20:05

这似乎适用于Vuetify 3: nofollow noreferrer“> htttps://blog..panda-panda-studio.cn/vue_comcomcom_webp_comcpond/ >

import LayoutVue from './layouts/LayoutVue.vue';
import { nextTick, createApp } from 'vue';

const myCustomLightTheme = {
    dark: false,
    colors: colors,
}

const vuetify = createVuetify({
    components: {
        VLayout,
        VAppBar,
        VNavigationDrawer,
        VMain,
        VContainer,
        VList,
        VListItem,
        // core journal components end
    },
    directives: {
        // resize,
    },
    icons: {
        defaultSet: 'fa',
        aliases,
        sets: {
            fa,
        },
    },
    theme: {
        defaultTheme: 'myCustomLightTheme',
        themes: {
            myCustomLightTheme,
        },
    },
})

customElements.define('layout-component', class extends HTMLElement {
    constructor() {
        super();
        nextTick(() => {
            var block_data = this.data || {};
            var app = createApp(LayoutVue, {
                data: block_data,
            }).mount(this);

            app.use(vuetify);
        })
    }
})

This seems to work for vuetify 3: https://blog.panda-studio.cn/vue_web_component_webpack_compiler

import LayoutVue from './layouts/LayoutVue.vue';
import { nextTick, createApp } from 'vue';

const myCustomLightTheme = {
    dark: false,
    colors: colors,
}

const vuetify = createVuetify({
    components: {
        VLayout,
        VAppBar,
        VNavigationDrawer,
        VMain,
        VContainer,
        VList,
        VListItem,
        // core journal components end
    },
    directives: {
        // resize,
    },
    icons: {
        defaultSet: 'fa',
        aliases,
        sets: {
            fa,
        },
    },
    theme: {
        defaultTheme: 'myCustomLightTheme',
        themes: {
            myCustomLightTheme,
        },
    },
})

customElements.define('layout-component', class extends HTMLElement {
    constructor() {
        super();
        nextTick(() => {
            var block_data = this.data || {};
            var app = createApp(LayoutVue, {
                data: block_data,
            }).mount(this);

            app.use(vuetify);
        })
    }
})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文