【发布时间】:2018-06-28 08:36:34
【问题描述】:
我将代码与./node_modules/.bin/webpack -d 捆绑在一起。除了class fields proposal,我没有将 ES6 编译为 ES5。
它给出了这个错误:
未捕获的类型错误:this.fetchTestExecutions 不是函数
代码如下:
import React from 'react'
import Config from 'Config'
class HomePage extends React.Component {
state = {
executions: this.fetchTestExecutions()
}
fetchTestExecutions = () => {
const host = Config.host
return fetch(`${host}/execution/index`)
.then(response => response.json())
.then(json => {
this.setState({executions: json})
})
}
render() {
return(
<div>
{ this.state.executions.map(x => <div>x.from</div>) }
</div>
)
}
}
export default HomePage
这是 webpack.config.js:
var webpack = require('webpack')
module.exports = {
entry: './src/App.jsx',
output: {
filename: './../public/bundle.js'
},
module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
query: {
plugins: ['transform-class-properties'],
presets: ['react'],
}
}
]
},
externals: {
'Config': JSON.stringify({host: "http://127.0.0.1:3000"})
}
}
怎么了?
感谢您的宝贵时间!
【问题讨论】:
标签: reactjs class ecmascript-6 arrow-functions