[英]Failed to mount component: template or render function not defined - vue warning when using Laravel-mix
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”,因为它不再具有确定目标的配置。
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 : {}
},
]
},
]
},
});
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.