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 接受不到的问题 #1628

Closed
patchBig opened this issue Dec 21, 2018 · 7 comments
Closed
Assignees

Comments

@patchBig
Copy link

微信小程序观察到,组件能正常接收到 props :
image

百度小程序观察到:
image

@taro-bot
Copy link

taro-bot bot commented Dec 21, 2018

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@Chen-jj
Copy link
Contributor

Chen-jj commented Dec 21, 2018

提供一下可复现的代码

@patchBig
Copy link
Author

组件

import { Block, View, Image } from '@tarojs/components'
import Taro from '@tarojs/taro'
import withWeapp from '@tarojs/with-weapp'

@withWeapp('Component')
class _C extends Taro.Component {
  static defaultProps = {
    show: false,
    title: '加载中'
  }
  state = {
    bgColor: '#fff'
  }
  _observeProps = []
  config = {
    component: true
  }

  render() {
    const { show: show, title: title } = this.props
    console.info("components render: this.props", this.props)
    return (
      <View
        className={Classnames({
          'page_loading': true,
          hide: !show
        })}
      >
      </View>
    )
  }
}

export default _C

page 中

import {
  Block,
  Form,
  View,
  Button,
  Text,
  Image,
  Input,
  ScrollView
} from '@tarojs/components'
import Taro from '@tarojs/taro'
import withWeapp from '@tarojs/with-weapp'
@withWeapp('Page')
class _C extends Taro.Component {
 constructor(props) {
    super(props);
  }
componentWillMount() {
 this.setState({
             showPageLoading: false
       })
  setTimeout(() => {
       this.setState({
             showPageLoading: true
       })
   }, 2000)
}
 render () {
   return (
      <View>
         <PageLoading show={showPageLoading} />
    </View>
  )
}
}

@Chen-jj
Copy link
Contributor

Chen-jj commented Dec 24, 2018

@patchBig 你提供的代码,render 函数里是有问题的,请打开 ESLint。

经调整你提供的代码,微信和百度小程序都没有问题。

page:

import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
import Child from '../../components/child/child'

export default class PageView extends Component {
  componentWillMount() {
    this.setState({
      showPageLoading: false
    })
    setTimeout(() => {
      this.setState({
        showPageLoading: true
      })
    }, 2000)
  }
  render () {
    return (
      <View>
        <Child show={this.state.showPageLoading} />
      </View>
    )
  }
}

component:

import Taro, { Component } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'

export default class Child extends Component {
  static defaultProps = {
    show: false
  }

  config = {
    component: true
  }

  render() {
    const { show: show } = this.props
    return (
      <View>{show}</View>
    )
  }
}

@taro-bot
Copy link

taro-bot bot commented Dec 24, 2018

Hello~

您的问题我们无法复现。如果有空的话还请拔冗提供一个简单的复现 demo,否则这个 issue 将在 15 天后被自动关闭。

如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。

Good luck and happy coding~

@callmedanieldaniel
Copy link

@patchBig 这个问题你解决了吗?我没找到解决办法

@Thehardtimesofbeans
Copy link

@danieltao1993
这种props支付宝没有问题
百度会有问题:按照上面给子组件中设置默认属性
默认属性对着你的子组件属性来即可
static defaultProps = {
show: false
}

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

4 participants