子组件给父组件传参只需这4步:
1.子组件wxml中绑定addInfo函数,
<button type="primary" bindtap="addInfo">确定</button>
2.子组件js中定义函数addInfo
addInfo(){
let item = {
title:'测试',
money:8,
category:'吃饭'
} //要传给父组件的参数
this.triggerEvent('addInfo',item) //通过triggerEvent将参数传给父组件
}
3.父组件wxml中绑定(接收)自定义点击函数
<add-item bind:addInfo="getAddInfo"></add-item>
4.父组件js中接收子组件传过来的参数
getAddInfo(e){
console.log(e.detail) //{title:'测试',money:8,category:'吃饭'}