小程序子组件向父组件传递数据

admin4年前公众号&小程序699

 绑定点击事件, 子组件触发父组件的自定义事件 this.triggerEvent("事件名",参数)向父组件传递参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//子组件js
Component({
    properties: {
        test_data:{
           type:Array,
           value:[]
        }
    },
    methods:{
       handleTap(e) {
          const index = e.currentTarget.dataset.index;
          this.triggerEvent("handlefatherEvent",index);
       }
    }
})

 

 

1
2
3
<!-- 父组件wxml -->
<child test_data="{{testData}}" bindhandleFatherEvent="handleFatherEvent">
</child>

 父组件绑定自定义事件,接收子组件传递数据

复制代码
0,apple,isActive:1,banana,isActive:2,grape,isActive:== =>i===index? v.isActive=:v.isActive=
复制代码
1
2
3
4
5
6
7
8
<!- 子组件wxml -->
<view class="child">
    <view class="child_item {{item.isActive===true?'active':''}}"
     wx:for="test_data"
     wx:key="id"
     bindtap="handleTap"<br>     data-index = {{index}}
    >{{item.name}}</view>
</view>


相关文章

微信公众号第三方h5页面登录

官方文档:https://developers.weixin.qq.com/doc/oplatform/Website_App/WeChat_Login/Wechat_Login.html参考文档:h...

附常见小程序 referer 的配置域名:

平台referer备注微信小程序https://servicewechat.com/{appid}/{version}/page-frame.html头条抖音https://tmaservice.de...

小程序添加远程仓库

https://developers.weixin.qq.com/miniprogram/dev/devtools/git.html...

小程序rich-text文字显示不全

含有><这样的符号,导致了标签开始闭合错乱,建议过滤为&lt;&gt;...

小程序添加分包的时候报错 “pages *** 不应该在分包 subPackages[*] 中”

分包和主包不能一个路径,可以这样写"root":"pages/weixiuConfirm"...

公众号自动登录php

public function isWeixin()     {       ...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。