父组件内设置的手电筒开关:
let childChat = this.selectComponent("#chatcomponent");
let flash = childChat.data.flash === "off"?"on":"off"
console.log(childChat);
childChat.setData({
"flash":flash
})
子组件数据是已经更新了的,但手电筒就是没反应这是咋回事?:
//这里使用setData()还会报错
observers:{
"flash":(flash)=>{
console.log("hahaha",flash)
}
},
s实在搞不懂

observers可以用箭头函数,flash更新完有没有还得看你的wxml怎么写
只要传,必报undefined,而普通的function就没事。
observers: {// 正常:'users': function({id}) {let t = thisusersApi.get({id,succeed(users) {t.setData({users})}})},// TypeError: Cannot read property 'setData' of undefined'users': ({id}) => {let t = thisusersApi.get({id,succeed(users) {t.setData({users})}})}}observers:{ "flash": function(flash){ console.log("hahaha",flash) } }observers别用箭头函数。