Use watch in the applet to monitor the parent's data

Foreword:

        In the applet, listen to the data from the parent in the child component. Note that the arrow function cannot be used, and this error is undefined

Instructions:

1. The parent binds data to the child

<message-list
    data="{
   
   {messageList}}"
 />

2. The child receives data

Component({
    //父级的字段
    properties: {
         data:Array,
    }


})

3. Children listen to data through observers

Note: Arrow functions cannot be used, and an error will be reported

observers: {
    'data': function (val) {
      if(val.length>0){
        this.handleDataFun(val)
      }
    },
}

Guess you like

Origin blog.csdn.net/qq_41619796/article/details/127869138