如何在ReactNative中使用ES6新语法

2025-05-23 02:12:06
推荐回答(1个)
回答1:

解决方法:
React工程需要webpack+babel
React-Native工程只需要在项目根目录放一个babel配置文件.babelrc即可
//.babelrc内容
{
"retainLines": true,
"compact": true,
"comments": false,
"whitelist": [
"es6.arrowFunctions",
"es6.blockScoping",
"es6.classes",
"es6.destructuring",
"es6.parameters",
"es6.properties.computed",
"es6.properties.shorthand",
"es6.spread",
"es6.modules",
"es6.templateLiterals",
"es7.trailingFunctionCommas",
"es7.objectRestSpread",
"es7.asyncFunctions",