Comments (10)
需要npm install --save-dev babel-preset-stage-1
然后将根目录下的.babelrc中的"stage-3" 修改为 “stage-1” 就可以使用修饰器了
from react-luo.
@javaLuo 这个需要我自己配置吗? 还是说您已经配置好了 ,我可以直接用?
from react-luo.
@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 (
)
}
}
运行项目时提示我识别不了@
from react-luo.
重新npm run dll 试试
from react-luo.
@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)
from react-luo.
额...不是吧,我这边测试可以识别@了
from react-luo.
@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 '@'
@ ./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
from react-luo.
我更新了代码,重新上传了。你再试试。
暂时取消了eslint代码检测。eslint现在的版本不支持decorator
from react-luo.
@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)
再次麻烦您给指导下了
from react-luo.
重新拉一下代码
重新install
那是react-router版本不兼容
暂时没有升级到react-router4.0
from react-luo.
Related Issues (20)
- 这个报错怎么回事:Warning: Hash history cannot PUSH the same path; a new entry will not be added to the history stack HOT 6
- css 样式里面的本地图片路径怎么打包到build里面 HOT 1
- css打包后怎么class名称后都加了这个后缀_7Z3_vq74 而html div 没有加后缀 导致样式名称不对 HOT 1
- 这个脚手架上怎么设置请求代理? HOT 3
- 内存溢出 HOT 5
- 服务器记录路由跳转 HOT 1
- 无法引入第三方样式 HOT 2
- ajax请求如何记录 HOT 1
- 引用相对路径图片 报错 HOT 4
- 切换成url 模式 模式报错 HOT 5
- 支持ssr HOT 2
- 添加对scss的支持 HOT 3
- mac上无法跑成功,node版本为8.11.0,同版本node可以在windows上跑通 HOT 11
- 有很多路由的时候,有什么简便的写法么? HOT 3
- 不做公共代码抽取么? HOT 1
- webpack5 HOT 3
- webpack 的loader配置应该不支持 antd 吧 HOT 3
- 开发ts版本 HOT 1
- 整个storybook HOT 1
- help! HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-luo.