原文链接:
Vue Render HTML - You may need an additional loader to handle the result of these loaders
环境:Vue 2.x
在 VueCli 中使用 render + jsx 报错:
Module parse failed: Unexpected token (224:36)
File was processed with these loaders:
* ./node_modules/cache-loader/dist/cjs.js
* ./node_modules/vue-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
报错代码:
headings: {
id: 'ID',
selected: function (h) {
return <b-form-checkbox v-model={this.checkedAll} onChange={this.selectAll}>
</b-form-checkbox>
}
}
解决方法:
安装 babel 插件:https://github.com/vuejs/babel-plugin-transform-vue-jsx
安装命令:
npm install babel-plugin-syntax-jsx babel-plugin-transform-vue-jsx babel-helper-vue-jsx-merge-props babel-preset-env --save-dev
在 babel.config.js 配置:
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}
每天都要被百度的辣鸡搜索结果气死,最后还是通过不可访问的搜索引擎,几秒搜到解决方案。stackoverflow YYDS
注:配置babel.config.js的前提是,项目安装了@vue/cli-plugin-babel,我使用的是@3.7.0版本。