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

原生语法页面调用taro语法组件不能触发声明周期 #4122

Closed
chenfaxiang opened this issue Aug 9, 2019 · 12 comments
Closed

原生语法页面调用taro语法组件不能触发声明周期 #4122

chenfaxiang opened this issue Aug 9, 2019 · 12 comments
Assignees
Labels
question Further information is requested

Comments

@chenfaxiang
Copy link

原生语法页面调用taro语法组件不能触发声明周期,这里有一个 demo ,帮忙看一下
fe_mp_all.zip

@taro-bot
Copy link

taro-bot bot commented Aug 9, 2019

欢迎提交 Issue~

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

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

Good luck and happy coding~

@chenfaxiang
Copy link
Author

chenfaxiang commented Aug 9, 2019

@yuche 麻烦大佬帮忙看一下这个问题,给点儿处理思路

@yuche
Copy link
Contributor

yuche commented Aug 12, 2019

哪个页面,怎么进入

@chenfaxiang
Copy link
Author

@yuche 我在项目 taro-sample-weapp 也做了一个 demo,这个比较清晰,这边提了一个 pull request ,demo 的入口文件是 src/pages/native/native.wxml,调用的对应 taro 组件是 src/components/tabTaro/tabTaro.js

@taro-bot
Copy link

taro-bot bot commented Aug 13, 2019

CC @Chen-jj

@Chen-jj
Copy link
Contributor

Chen-jj commented Aug 13, 2019

@chenfaxiang tabTaro 组件的生命周期会被触发。

image

@chenfaxiang
Copy link
Author

@Chen-jj 老哥,不好意思,这里是之前提的一个,描述有误,在 taro-sample-weapp 这个项目的 pull request 里面的测试我也发现了生命周期可以正常执行;最终的问题是这样,我们在 taro 的原生组件中调用用 taro 语法写的组件时,taro 组件语法写的组件中的传参和事件不会被执行。

@Chen-jj
Copy link
Contributor

Chen-jj commented Aug 13, 2019

@chenfaxiang demo

@chenfaxiang
Copy link
Author

@Chen-jj demo 就是 taro-sample-weapp 项目的这个 pull request,在文件 pages/native/native.js 中定义了一个 taroHandler 事件,在 pages/native/native.wxml 中的组件 tabNative 调用上绑定了属性 myProperty 和事件 tabHandler ,之后在 taro 语法写的子组件 tabNative.js 中属性 myProperty 没有接收到,onClick 点击事件也不会被触发。

@Chen-jj
Copy link
Contributor

Chen-jj commented Aug 15, 2019

@chenfaxiang 原生组件传 props 给 Taro 组件需要通过 extraProps

@Chen-jj Chen-jj added answered question Further information is requested labels Aug 15, 2019
@Chen-jj
Copy link
Contributor

Chen-jj commented Aug 15, 2019

@chenfaxiang

native.js:

Page({
  onReady() {
    this.setData({
      extraProps: {
        myProperty: '+++++++++++++++++++taro component',
        taroHandler: this.taroHandler
      }
    })
  }
})

native.wxml:

<tabNative extraProps="{{extraProps}}"></tabNative>

tabTaro.js:

Component({
  clickHandler = () => {
    console.log(this.props.myProperty)
    this.props.taroHandler()
  }
})

@taro-bot
Copy link

taro-bot bot commented Aug 15, 2019

Hello~

您的问题楼上已经有了确切的回答,如果没有更多的问题这个 issue 将在 15 天后被自动关闭。

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

Good luck and happy coding~

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

No branches or pull requests

4 participants