【vue】---vue中使用async+await出现的问题及解决方案

一、在Vue中出现的问题

  因为我没有用脚手架,自己用webpack配置的环境,因此报了以下错误,出现的问题应该是缺少解析器的原因

二、解决方案

安装:

  npm i babel-plugin-transform-runtime --save-dev

  npm i babel-runtime --save

npm i babel-plugin-transform-runtime --save-dev
npm i babel-runtime --save

其次在目录的.babelrc中添加如下配置

"plugins":["transform-runtime"]

三、babel-plugin-transform-runtime

在转换 ES2015 语法为 ECMAScript 5 的语法时,babel 会需要一些辅助函数,例如 _extend。babel 默认会将这些辅助函数内联到每一个 js 文件里,这样文件多的时候,项目就会很大。

所以 babel 提供了 transform-runtime 来将这些辅助函数“搬”到一个单独的模块 babel-runtime 中,这样做能减小项目文件的大小。

因为babel编译es6到es5的过程中,babel-plugin-transform-runtime这个插件会自动polyfill es5不支持的特性,这些polyfill包就是在babel-runtime这个包里,所以babel-runtime需要安装在dependency而不是devDependency。

猜你喜欢

转载自www.cnblogs.com/nanianqiming/p/11111913.html