在使用webpack编译代码后,在状态之后 = 上面对意外令牌错误。我的代码如下:
class GroceryItem extends React.Component {
state = {
labelValue: "Hello Pages"
};
render() {
return ( < div onClick = {
this.state.labelValue
} > ded
<
/div>);
}
}
我尝试过在StackOverflow上找到的各种方法,但似乎都没有。
.bablerc
{
"presets" : ["es2015", "react"]
}
.webpack..config.js
var webpack = require('webpack');
var path = require('path');
var BUILD_DIR = path.resolve(__dirname, 'public/js/');
var APP_DIR = path.resolve(__dirname, 'src/components');
var config = {
entry: APP_DIR + '/main.jsx',
output: {
path: BUILD_DIR,
filename: 'bundle.js'
},
module : {
loaders : [
{
test : /\.jsx?$/,
include : APP_DIR,
loader : 'babel',
query:{
presets: ['react']
}
}
]}
};
module.exports = config;
答案 0 :(得分:2)
您需要babel-preset-stage-x
预设来声明类似的类。
见repl
{
presets: ["react", "es2015", "stage-2"]
}