父級(jí)給子組件傳值:
在父級(jí)中調(diào)用組件
<get_chance id="get_chance" active_info="{{active_info}}" member_data="{{member_data}}" add_status="{{add_status}}"> </get_chance>
在子組件js中獲取
properties: {
active_info: { // 屬性名
type: Object, // 類型(必填),目前接受的類型包括:String, Number, Boolean, Object, Array, null(表示任意類型)
value: '' // 屬性初始值(可選)涉茧,如果未指定則會(huì)根據(jù)類型選擇一個(gè)
},
add_status: {
type: Boolean,
value: ''
},
member_data: {
type: Object,
value: ''
}
},
子組件給父級(jí)傳值
在子組件中
PublicFunA.add_chance(args).then(function (res) {
// console.log(res.data)
//更新玩家數(shù)據(jù)
PublicFunA.lucky_member().then(function (res) {
console.log(res.data)
if(res.data.wx_chance == 1){
that.setData({
focus_status: true,
})
}
** //重點(diǎn)曼玩,將請(qǐng)求到的數(shù)據(jù)傳給父級(jí)**
let myEventDetail = {
val: res.data
}
that.triggerEvent('compontpass', myEventDetail)
})
父級(jí) html
<get_chance id="get_chance" bind:compontpass="compontpass"> </get_chance>
父級(jí)js
//父組件接收子組件傳來的值,更新玩家數(shù)據(jù)
compontpass: function (e) {
// if(e.detail.val){}
// console.log(e.detail.val);
this.setData({
member_data: e.detail.val
})
},