美文网首页JavaScript
Using the export keyword between

Using the export keyword between

作者: 小小小小的人头 | 来源:发表于2019-05-15 10:53 被阅读20次

最近用create-react-app 生成脚手架-想写一下mobx的demo的;然后随便在一个页面内上加了个修饰器。就出现了这样的错;

image.png
网上也搜索了。好像很多都行不通。 应该是babel 升级到7的原因;先给出一个可以亲测已经通过的方案。
如果也有学习mobx的话,自己也写了mobx的demo creact-react-app-mobx demo
react-native项目需要配置修饰器的参考链接
1.下载依赖
npm install --save customize-cra 
npm install --save react-app-rewired 
npm install --save @babel/plugin-proposal-decorators 
2.在根目录创建项目config-overrides.js
const { override, addDecoratorsLegacy } = require('customize-cra');
module.exports = override(
 addDecoratorsLegacy()
 );
3.修改package.json 启动配置
"scripts": {
 "start": "react-app-rewired start",
 "build": "react-app-rewired build",
 "test": "react-app-rewired test",
 "eject": "react-app-rewired eject"
  },

然后重新 npm start 一下就可以了。 but 这边有一个瑕疵的地方就是
修饰器放在export default 还是报之前的错;

@testable //修饰器
export default class Two extends Component {
  constructor(props) {
    super(props);
    this.state = {};
  }
}

如果我换成下方的写法。修饰器 放在 class之前就没错了。我也不知道为什么。 我继续学习。我解决了会及时更新的---如果有知道为什么的也可以指导下;

export default @testable class Two extends Component {
  constructor(props) {
    super(props);
    this.state = {};
  }
}

这文章主要是先解决 脚手架不支持修饰器的问题。 后面也会学习其他的解决办法。 有大佬有其他解决方案 也希望留言。 ~

相关文章

网友评论

    本文标题:Using the export keyword between

    本文链接:https://www.haomeiwen.com/subject/fahnwqtx.html