javaLuo / react-luo

React Automatically - 保持最新技术 react18 hooks router6 webpack5 babel7 antd4
https://isluo.com/work/pwa/
MIT License
312 stars 71 forks source link

请指点,万分感激 #2

Closed wangjunwei910208 closed 7 years ago

wangjunwei910208 commented 7 years ago

您好,首先您搭的这个框架功能很齐全,但我克隆后,想在这个基础上为redux的connect方法配置装饰器,比如下面这种写法 @connect( state => ({ num:state.app.num }), dispatch =>({ action: bindActionCreators(actionA, dispatch) }); 这个要如何配置,您方便更新下吗?

javaLuo commented 7 years ago

需要npm install --save-dev babel-preset-stage-1 然后将根目录下的.babelrc中的"stage-3" 修改为 “stage-1” 就可以使用修饰器了

wangjunwei910208 commented 7 years ago

@javaLuo 这个需要我自己配置吗? 还是说您已经配置好了 ,我可以直接用?

wangjunwei910208 commented 7 years ago

@javaLuo 根据您的提示,修改后,这样编辑,如下: @connect( state => ({ num: state.app.num, }), dispatch =>({ }) ) class Mytest extends React.Component { constructor(props) { super(props); this.state = { }; } render() { const {num} = this.props; console.log(num); return (

    )
}

} 运行项目时提示我识别不了@

javaLuo commented 7 years ago

重新npm run dll 试试

wangjunwei910208 commented 7 years ago

@javaLuo 还是 报这个错 ERROR in ./src/a_container/test/index.js

C:\Users\Administrator\Desktop\react_luo\src\a_container\test\index.js 142:1 error Parsing error: Unexpected character '@'

✖ 1 problem (1 error, 0 warnings)

javaLuo commented 7 years ago

额...不是吧,我这边测试可以识别@了

wangjunwei910208 commented 7 years ago

@javaLuo 我从新拷贝你的项目 然后按您的指示,报如下错误: ERROR in ./src/a_container/test/index.js

C:\Users\Administrator\Desktop\react+redux\react_luo\src\a_container\test\index. js 143:1 error Parsing error: Unexpected character '@'

✖ 1 problem (1 error, 0 warnings)

@ ./src/route/index.js 25:14-50 @ ./src/app.js @ multi webpack-dev-server/client?http://localhost:8888 webpack/hot/dev-server ./src/app

ERROR in ./src/a_container/test/index.js Module build failed: SyntaxError: C:/Users/Administrator/Desktop/react+redux/rea ct_luo/src/a_container/test/index.js: Decorators are not officially supported ye t in 6.x pending a proposal update. However, if you need to use them you can install the legacy decorators transform with:

npm install babel-plugin-transform-decorators-legacy --save-dev

and add the following line to your .babelrc file:

{ "plugins": ["transform-decorators-legacy"] }

The repo url is: https://github.com/loganfsmyth/babel-plugin-transform-decorator s-legacy.

148 | }) 149 | )

150 | class Mytest extends React.Component { | ^ 151 | constructor(props) { 152 | super(props); 153 | this.state = {

@ ./src/route/index.js 25:14-50 @ ./src/app.js @ multi webpack-dev-server/client?http://localhost:8888 webpack/hot/dev-server ./src/app 然后我这样: npm install babel-plugin-transform-decorators-legacy --save-dev

接着修改.babelrc { "presets": ["es2015", "stage-1", "react"], "plugins": [ "transform-decorators-legacy", ["import", { "libraryName": "antd", "style": "css" } ] ] } 最后运行时还是报错 C:\Users\Administrator\Desktop\react+redux\react_luo\src\a_container\test\index.js 143:1 error Parsing error: Unexpected character '@'

✖ 1 problem (1 error, 0 warnings)

@ ./src/route/index.js 25:14-50 @ ./src/app.js @ multi webpack-dev-server/client?http://localhost:8888 webpack/hot/dev-server ./src/app

javaLuo commented 7 years ago

我更新了代码,重新上传了。你再试试。 暂时取消了eslint代码检测。eslint现在的版本不支持decorator

wangjunwei910208 commented 7 years ago

@javaLuo 您好,现在能识别@了,但是运行后会报这个错,如下: vendor.dll.js:34 Uncaught TypeError: Cannot read property 'location' of undefined at new t (vendor.dll.js:34) at d._constructComponentWithoutOwner (vendor.dll.js:43) at d._constructComponent (vendor.dll.js:43) at d.mountComponent (vendor.dll.js:43) at Object.mountComponent (vendor.dll.js:20) at d.performInitialMount (vendor.dll.js:43) at d.mountComponent (vendor.dll.js:43) at Object.mountComponent (vendor.dll.js:20) at d.performInitialMount (vendor.dll.js:43) at d.mountComponent (vendor.dll.js:43) 再次麻烦您给指导下了

javaLuo commented 7 years ago

重新拉一下代码 重新install 那是react-router版本不兼容 暂时没有升级到react-router4.0