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

预加载this.$preloadData是undefined #1476

Closed
zhcode-fun opened this issue Dec 12, 2018 · 4 comments
Closed

预加载this.$preloadData是undefined #1476

zhcode-fun opened this issue Dec 12, 2018 · 4 comments
Assignees

Comments

@zhcode-fun
Copy link

问题描述
componentWillMount 中获取不到this.$preloadData
打印出来是undefined

复现步骤
[复现问题的步骤]
例如:A页面跳转至B页面

  • A页面简单跳转事件
export default class A extends Component {
  config = {
    navigationBarTitleText: '首页'
  }
  click(param) {
    Taro.navigateTo({
      url: '/pages/preload/preload?url=hello'
    })
  }

  render () {
    return (
      <View className='index'>
        <Text>Hello world!</Text>
        <View onClick={this.click}>
          <Text>点击跳转</Text>
        </View>
      </View>
    )
  }
}
  • B页面(就是文档里的例子)
export default class B extends Component {
  constructor() {
    super(...arguments);
  }
  config = {
    navigationBarTitleText: '预加载页面'
  };
  componentWillMount () {
    console.log('isFetching: ', this.isFetching)
    this.$preloadData
      .then(res => {
        console.log('res: ', res)
        this.isFetching = false
      })
  }

  componentWillPreload (params) {
    return this.fetchData(params.url)
  }

  fetchData () {
    this.isFetching = true;
  }
  render() {
    return (
      <View className='container'>
           <Text>B页面</Text>
      </View>
    );
  }
}

期望行为
正常使用this.$preloadData获取到值

报错信息

[这里请贴上你的完整报错截图或文字]
image

系统信息

  • 操作系统: win10

  • Taro 版本
    image

  • Node.js 版本
    image

  • 报错平台
    weapp

补充信息

@taro-bot
Copy link

taro-bot bot commented Dec 12, 2018

欢迎提交 Issue~

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

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

Good luck and happy coding~

@taro-bot
Copy link

taro-bot bot commented Dec 12, 2018

CC @Chen-jj

@luckyadam
Copy link
Member

目测是由于 fetchData 没有返回数据,这个例子不是很完整,你可以在 fetchData 里返回一个 promise 试试

@zhcode-fun
Copy link
Author

目测是由于 fetchData 没有返回数据,这个例子不是很完整,你可以在 fetchData 里返回一个 promise 试试

那建议可以修改一下文档的例子,我还以为返回的数据是taro自动封装到promise里面的呢

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

3 participants