简体   繁体   English

无法安装组件:模板或渲染函数未定义-使用Laravel-mix时出现vue警告

[英]Failed to mount component: template or render function not defined - vue warning when using Laravel-mix

The problem 问题

I created the frontend of a project in Vue2. 我在Vue2中创建了一个项目的前端。 I used a plugin called 'vue-svg-inline-loader' to convert my svg images to inline svg code. 我使用了一个名为“ vue-svg-inline-loader”的插件将我的svg图像转换为嵌入式svg代码。 In order to get the script to work I had to add this config code to my vue.config.js. 为了使脚本正常工作,我必须将此配置代码添加到我的vue.config.js中。

The team has now implemented the frontend on the backend (Laravel) using Laravel-mix. 团队现在已经使用Laravel-mix在后端(Laravel)上实现了前端。 This broke my "vue-svg-inline-loader" as it does not have the config anymore to figure out what to target. 这破坏了我的“ vue-svg-inline-loader”,因为它不再具有确定目标的配置。

Code that I've tried 我尝试过的代码

I read a lot of questions and answers on StackOverflow but this kind of configuration seem so vast I cannot seem to put my finger on how shoul I write it. 我在StackOverflow上阅读了很多问题和答案,但是这种配置看起来是如此庞大,以至于我似乎无法对我编写它的方式投入多少精力。 I believe that from my attempt, I am missing the rule(vue) from my previous file and the use("vue-svg-inline-loader") which was pointing to the plugin. 我相信,从我的尝试中,我丢失了先前文件中的rule(vue)和指向插件的use(“ vue-svg-inline-loader”)。

My previous vue.config.js which was working 我以前的vue.config.js正在运行

module.exports = {
    css: {
        loaderOptions: {
            sass: {
                data: `@import "@/css/all.scss";`
            }
        }
    },
    chainWebpack: config => {
        config.module
            .rule("vue")
            .use("vue-svg-inline-loader")
                .loader("vue-svg-inline-loader")
                .options({ /* ... */ });
    }
}

My attempt at webpack.mix.js 我在尝试webpack.mix.js

mix.webpackConfig({
    module : {
        rules : [
            'vue',
            {
                use : [
                    'vue-svg-inline-loader',
                    {
                        loader: 'vue-svg-inline-loader',
                        options : {}
                    },
                ]
            },
        ]
    },
});

Updates 更新

Update 26 Aug: I managed to get in touch with the dev of vue-svg-inline-loader. 8月26日更新:我设法与vue-svg-inline-loader的开发人员联系。 We worked on some leads and managed to get to this: 我们致力于一些潜在客户,并设法做到这一点:

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')
    .copy('resources/assets', 'public/assets', true)
    .webpackConfig({
        module: {
            rules: [
                {
                    use: [
                        {
                            loader: "vue-svg-inline-loader",
                            options: {
                                    inline: {
                                        keyword: "svg-inline",
                                        strict: true
                                    }
                            }
                        }
                    ]
                }
            ]
        }
    });

With this it loads all the SVGs properly but it does not load any img that uses an image in a different format than SVG. 这样,它可以正确加载所有SVG,但不会加载任何使用与SVG格式不同的图像的img。 I thought it's a rule or a test problem, therefore I added test: /\\.vue$/, . 我认为这是一个规则或测试问题,因此我添加了test: /\\.vue$/, . test: /\\.vue$/, With this I encountered errors of missing vue-loader so I added vue-loader as well. 这样我遇到了缺少vue-loader的错误,所以我也添加了vue-loader With vue-loader declared, the code compiled. 使用vue-loader声明后,将编译代码。 When I accessed the app only a blank page returned along with the following console error: [Vue warn]: Failed to mount component: template or render function not defined. 当我访问该应用程序时,仅返回一个空白页以及以下控制台错误: [Vue warn]: Failed to mount component: template or render function not defined.

The final, not working code looks like: 最终的不起作用的代码如下所示:

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')
    .copy('resources/assets', 'public/assets', true)
    .webpackConfig({
        module: {
            rules: [
                {
                    test: /\.vue$/,
                    use: [
                        {
                            loader: "vue-loader",
                            options: { /* ... */ }
                        },
                        {
                            loader: "vue-svg-inline-loader",
                            options: {
                                    inline: {
                                        keyword: "svg-inline",
                                        strict: true
                                    }
                            }
                        }
                    ]
                }
            ]
        }
    });

Managed to get to a solution along with the Laravel Mix team. 设法与Laravel Mix团队一起找到解决方案。 I have also informed the developer of vue-svg-inline-loader and this solution should be now featured in their documentation. 我还通知了vue-svg-inline-loader开发人员,该解决方案现在应该在他们的文档中介绍。

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')
    .copy('resources/assets', 'public/assets', true)
    .override(config => {
        config.module.rules.push({
            test: /\.vue$/,
            use: [{ loader: 'vue-svg-inline-loader' }]
        })
    });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel - [Vue 警告]:无法挂载组件:未定义模板或渲染函数 - Laravel - [Vue warn]: Failed to mount component: template or render function not defined Vue警告:无法安装组件:未定义模板或渲染功能 - Vue warn: Failed to mount component: template or render function not defined Vue.js 2- 无法安装组件:模板或渲染 function 未定义 - Vue js 2- Failed to mount component: template or render function not defined Vue.js 无法挂载组件:未定义模板或渲染函数 - Vue.js Failed to mount component: template or render function not defined 如何修复无法挂载组件:vue 中未定义模板或渲染函数 - how to fix Failed to mount component: template or render function not defined in vue Vue 无法挂载组件:未定义模板或渲染函数 - Vue Failed to mount component: template or render function not defined (Vue with Typescript) 无法挂载组件:未定义模板或渲染函数 - (Vue with Typescript) Failed to mount component: template or render function not defined Gulp [Vue 警告]:无法挂载组件:未定义模板或渲染函数 - Gulp [Vue warn]: Failed to mount component: template or render function not defined 生成Vue项目时出现错误“无法安装组件:模板或渲染功能未定义” - Getting an error “Failed to mount component: template or render function not defined” when I building a Vue project 尽管使用了完整的编译器捆绑包,但Vue中的“无法安装组件:模板或渲染功能未定义” - “Failed to mount component: template or render function not defined” in Vue, despite using full compiler bundle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM