TypeError: Cannot read property 'setState' of undefined
import Taro, { Component } from '@tarojs/taro'
import { View, Text, Button } from '@tarojs/components'
import './index.less'
export default class Index extends Component {
config = {
navigationBarTitleText: '首页'
}
state = {
name:'里斯'
}
componentWillMount () { }
componentDidMount () {
// this.setState({name:'李四'})
}
componentWillUnmount () { }
componentDidShow () { }
componentDidHide () { }
click(){
this.setState({name:'章祠'});
}
render () {
return (
<View className='index'>
<Button onClick={this.click}>改变名字</Button>
<Text>{this.state.name}</Text>
</View>
)
}
}