ReactNative使用mobx @observer装饰器报错

2019-05-09  本文已影响0人  会飞的鱼儿_0012

要支持ES7 decorator属性,需要安装babel插件
新版本RN使用babel@7.0+,要和老版本做区分

1.安装babel

// RN版本0.57之前安装
npm install --save-dev babel-plugin-transform-decorators-legacy babel-preset-react-native-stage-0 
// RN版本0.57之后安装
npm install --save-dev @babel/plugin-proposal-decorators

2.创建babel.config.js文件,配置babel

// RN版本0.57之前配置
module.exports = {
  "presets": ["react-native"],
  "plugins": ["transform-decorators-legacy"]
};
// RN版本0.57之后配置
module.exports = {
  presets: ["module:metro-react-native-babel-preset"],
  plugins: [["@babel/plugin-proposal-decorators", { legacy: true }]]
};
上一篇 下一篇

猜你喜欢

热点阅读