Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

获取不到props #4310

Closed
mihuartuanr opened this issue Aug 27, 2019 · 4 comments
Closed

获取不到props #4310

mihuartuanr opened this issue Aug 27, 2019 · 4 comments

Comments

@mihuartuanr
Copy link

mihuartuanr commented Aug 27, 2019

Taro1.2.0
使用的是taro init myApp安装的环境,有redux包,在此前提下。

image

....
  static defaultProps = {
    configuration: {
      checkedAllAirCondition: 1,
      location: 1,
      dateRange: 1,
      status: 1,
    }
  }

....

  constructor (props) {
    super(props)
    console.log('------======')
    console.log(this.props)

....

constructor中打印出来的this.props是我默认设置的defaultProps,而始终获取不到我通过组件属性传递过来的值,去掉defaultProps,获取到的是undefined

打印thisredux的数据对象。

#1545

@Chen-jj
Copy link
Contributor

Chen-jj commented Aug 27, 2019

@mihuartuanr 哪个端,贴完整代码文本

@mihuartuanr
Copy link
Author

@mihuartuanr 哪个端,贴完整代码文本

微信小程序,可以看#1545,大体一致。或者,我稍后传一下代码。

@mihuartuanr
Copy link
Author

调用ConditionFilter组件

  render () {
    return (
      <View className='index'>
        <ConditionFilter
         configuration='123'
        ></ConditionFilter>
      </View>
    )
  }

ConditionFilter组件

@connect(({ counter }) => ({
  counter
}), (dispatch) => ({
  add () {
    dispatch(add())
  },
  dec () {
    dispatch(minus())
  },
  asyncAdd () {
    dispatch(asyncAdd())
  }
}))
class ConditionFilter extends Component {
  static defaultProps = {
    configuration: {
      checkedAllAirCondition: 1,
      location: 1,
      dateRange: 1,
      status: 1,
    }
  }
  config = {
    "navigationStyle": "custom",
    usingComponents: {
      "vant-button": "../vant-weapp/button/index",
      "vant-row": "../vant-weapp/row/index",
      "vant-col": "../vant-weapp/col/index",
      "vant-popup": "../vant-weapp/popup/index",
      "custom-tree-select": "./custom-tree-select/custom-tree-select"
    }
  }

  constructor (props) {
    super(props)
    console.log('------======')
    console.log(this.props)
    this.state = {
      popup: {
        show: false,
        position: 'top',
      },
      allAirConditionChecked: false,
      dateRange: [],
      status: '',
      location: '',
    }
  }

  componentWillReceiveProps (nextProps) {
    console.log('-===---===componentWillReceiveProps')
    console.log(this.props, nextProps)
  }

  componentWillUnmount () { }

  componentDidShow () { }

  componentDidHide () { }
  openLocalPopup() {
    console.log('-----=======openLocalPopup')
    this.setState({
      popup: {
        show: true,
        position: 'left',
      }
    })
  }
  openStatusPopup() {
    console.log('-----=======openStatusPopup')
    this.setState({
      popup: {
        show: true,
        position: 'top',
      }
    })
  }
  openDatePopup() {
    console.log('-----=======openDatePopup')
    this.setState({
      popup: {
        show: true,
        position: 'top',
      }
    })
  }
  onClose() {
    const popupStatus = this.state.popup;
    this.setState({
      popup: Object.assign(
        {},
        popupStatus,
        {
          show: false,
        }
      ),
    })
    console.log('----=====zx')
  }
  render () {
    const {configuration: conf} = this.props
    return (
      <View>
        <vant-row>
          <vant-col span="5">
            {conf.checkedAllAirCondition && (<vant-button round plain>全选</vant-button>)}
          </vant-col>
          <vant-col offset="4">
            <vant-row>
              {
                conf.location && (
                  <vant-col span="12">
                    <vant-button plain onClick={this.openLocalPopup.bind(this)}>位置</vant-button>
                  </vant-col>
                )
              }
              {
                conf.status && (
                  <vant-col span="12">
                    <vant-button plain onClick={this.openStatusPopup.bind(this)}>状态</vant-button>
                  </vant-col>
                )
              }
              {
                conf.dateRange && (
                  <vant-col span="12">
                    <vant-button plain onClick={this.openDatePopup.bind(this)}>时间</vant-button>
                  </vant-col>
                )
              }
            </vant-row>
          </vant-col>
        </vant-row>
        <vant-popup
          custom-class='left-popup'
          show={popup.show}
          position={popup.position}
          overlay={true}
          onClose={this.onClose}
        >
          <custom-tree-select></custom-tree-select>
        </vant-popup>
      </View>
    )
  }
}

@mihuartuanr
Copy link
Author

@mihuartuanr 哪个端,贴完整代码文本

不用看了,我升级了@tarojs/cli1.3.15就没问题了...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants