0

我有一些自定义组件

//father-component.wxml
<view class = "wrapper">
  <! - more code ->
  <slot> </slot>
</view>


//my_table.wxml
<view class = "wrapper">
  <! - more code ->
  <slot> </slot>
</view>

<son-component>可以是几个自定义组件

所以它是这样实例化的:

<father-component>
 <my_table>
   <son-component wx: for = "{{collection}}" wx: key = "index">
     <! - ... ->
   </son-component>
  </my_table>
</father-component>

当 for 循环结束时,我需要捕获“父组件”的高度。现在我在附件中创建了捕获高度的值:

attached () {
      let that = this;
      const query = wx.createSelectorQuery().in(this)
      query.select('.wrapper').boundingClientRect(function(res){
        that.data.height = res.height
      }).exec()
    },

但它返回的是组件具有的初始值,而不是循环结束时的值。

是否可以将观察者添加到父组件的本机高度属性,以便在添加孙子时我可以捕获它?

4

0 回答 0