微信小程序自定义组件传值问题
父组件(引用组件的页面模板)页面

子组件页面

<slot></slot>表示父组件页面往子组件插入的内容,
效果图


父组件传值子组件
看img1 child="{{child}}",直接绑定就可以传值到自组件
自组件需要通过properties才能接受参数,properties里面的值类似data的值,直接绑定使用就行。

子组件传值父组件
本实例使用tap点击事件传值到父组件,见img2。

子组件传值之后父组件还需要接受子组件传来的值,在父组件的组件 bind:myevent='getChild'来绑定,在调用的getChild函数中获取,获取后setData,再在页面引用。

写的比较粗浅,希望对大家有帮助,一起加油!
网友评论