Attribute monitoring in mini programs

        Usage scenario: In the process of completing the design, in order to achieve the purpose of displaying more content and improving user experience through bottom loading, what changes when bottoming out at the parent level is the content of the subcomponent, so it is necessary to always load in the subcomponent. Monitor the data changes of the parent component.

1.Introduce child components into the .json file of the parent component

"usingComponents": {
    "articleList":"../../components/articleList/articleList",
  }

2. Bind data to the child component in the parent component

<articleList num="{
    
    {number}}"></articleList>

3. The child component accepts the data passed by the parent component

properties:{
    num:Number,//请求列表的数量
  },

4. Use observers to implement property monitoring of the parent component by the subcomponent ( note that arrow functions cannot be used here )

observers: {
    'num': function (val) {
      console.log(val,"父组件的值发生改变");
      this.getArticle(val)//此方法为处理子组件中内容变化的方法
    },
  },

Guess you like

Origin blog.csdn.net/gkx19898993699/article/details/130522446