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

admin3年前公众号&小程序582

 绑定点击事件, 子组件触发父组件的自定义事件 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>


相关文章

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

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

小程序最新版获取头像和昵称

https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/userProfile.html...

小程序添加远程仓库

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

小程序添加客服

其实只需要解决2个问题第一步,在微信小程序中添加联系在线客服按钮第二步,接入在线客服功能,设置【自动/人工/转人工】回复等一、添加小程序客服按钮① 在小程序中添加客服按钮功能,点此参考官方文档(开发者...

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

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

公众号自动登录php

public function isWeixin()     {       ...

发表评论    

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