taro
taro copied to clipboard
state & props 关键字在 render 方法里的异常
问题描述 无法在 render 方法里面正常使用 state, props 变量
复现步骤
import Taro, { Component } from '@tarojs/taro'
import { View, Image } from '@tarojs/components'
export default class AddressWithOrder extends Component {
constructor(...rest) {
super(...rest)
this.state = {
someThing: '123123',
}
}
render () {
const {state} = this;
return (
<View className='address-order'>
{state.someThing + ''}
</View>
)
}
}
// 以及
import Taro, { Component } from '@tarojs/taro'
import { View, Image } from '@tarojs/components'
export default class AddressWithOrder extends Component {
constructor(...rest) {
super(...rest)
}
render () {
const {props} = this;
return (
<View className='address-order'>
{props.someThing + ''}
</View>
)
}
}
AddressWithOrder.defaultProps = {
someThing: 123,
}
期望行为 有时候想要在 JSX 里能够直接看到所渲染的数据是来自 state 还是 props 的,所以希望它们能够正常工作
报错信息

系统信息
- 操作系统: [e.g. Windows 10]
- Taro 版本 [e.g. v.0.0.64]
- Node.js 版本 [e.g. v9.0.0]