webpack 升级4.x vue 渲染出错 - Go语言中文社区

webpack 升级4.x vue 渲染出错


webpack 升级4.x vue 渲染出错

原因

webpack4.x 更新
webpack 对于import 的语法实现更新
注:import 是 ES6标准,但不是服务器端node 的标准,这里webpack相当于解析器,变相支持 import 语法,但不是说node环境支持import 语法.
从webpack 4.x 起 import 返回值 始终为一个对象.
但是vue 渲染只支持 template 或者 render function.

解决方法

做以下修改,从对象中取出默认的渲染函数或模板
vue-loader 尤大 的说明

/*
Breaking Changes
The esModule option is now true by default, because this is necessary for ES-module-based scope hoisting to work. This means the export from a *.vue file is now an ES module by default, so async components via dynamic import like this will break:
*/
const Foo = () => import('./Foo.vue')
/*
Note: the above can continue to work with Vue 2.4 + vue-router 2.7, which will automatically resolve ES modules' default exports when dealing with async components. In earlier versions of Vue and vue-router you will have to do this:
*/
const Foo = () => import('./Foo.vue').then(m => m.default)
/*Alternatively, you can turn off the new behavior by explicitly using esModule: false in vue-loader options.

Similarly, old CommonJS-style requires will also need to be updated:
*/
// before
const Foo = require('./Foo.vue')

// after
const Foo = require('./Foo.vue').default
版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_29594393/article/details/86572390
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-02-25 01:24:21
  • 阅读 ( 1407 )
  • 分类:前端

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢