VUE组件懒负载SVG

发布于 2025-02-13 06:17:48 字数 594 浏览 0 评论 0原文

我试图在我的组件加载时试图lazy加载SVG,但是运行npm运行手表,并且组件尝试构建它正在尝试找到此文件,当然,当组件被汇总到路径上时是懒惰的加载会有所不同,因此目前我遇到了一个错误,指出它无法找到文件。

我的组件将汇编为public_html/Assets/js/chunks/[hash] .js,我的SVG将在public> public_html/assets/icons/icons/icons/manducturer.svg之内。

如何停止尝试编译路径并仅将其加载到负载上?

// component

    computed: {
        icon() {
            const icons = {
                manufacturer: () => import('../../icons/manufacturer.svg')
            }
            return icons['manufacturer'];
        },

im trying to lazy load an SVG when my component loads, however when running npm run watch and the component attempts to build it is trying to find this file, of course when the component is compiled down the path it is lazy loading will be different, so i'm getting an error at the moment stating it's unable to locate the file.

My component will compile down to public_html/assets/js/chunks/[hash].js, and my SVG will be within public_html/assets/icons/manufacturer.svg.

How can I stop it trying to compile the path and only load it on load?

// component

    computed: {
        icon() {
            const icons = {
                manufacturer: () => import('../../icons/manufacturer.svg')
            }
            return icons['manufacturer'];
        },

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文