收藏
回答

自定义组件内如果通过this.createSelectQuery查询slot的节点信息?

组件生命周期函数ready中查询slot的节点信息,返回结果为null

ready() {
         const { scrollIntoView } = this.properties;
         // <slot id="{{scrollIntoView}}" name="content"></slot>,获取slot的位置.
         const query = this.createSelectorQuery();
         query.select(`#${scrollIntoView}`).boundingClientRect();
         query.selectViewport().scrollOffset();
         query.exec((res) => {
            console.log("scrollIntoView", res);
         });
      },


<view class="scroll-box column">
   <view class="outer-scroll {{ styleConfig.back }}">
      <scroll-view
         scroll-y="true"
         enable-flex="true"
         enable-passive="true"
         enhanced="true"
         scroll-into-view="{{scrollIntoView}}"
         scroll-into-view-alignment="start"
         bindscrolltolower="bindscrolltouppernew"
      >
         <slot id="{{scrollIntoView}}" name="content"></slot>
         <view class="scroll_bottom"> </view>
      </scroll-view>
      <view class="scroll-bar {{ styleConfig.back + ' ' + styleConfig.border['top'] }}">
         <slot name="bar"></slot>
      </view>
   </view>
   <view class="bottom-bar flex_space safe_area_margin">
      <button class="center btn_empty radius_100 {{ styleConfig.button }}">
         <text class="{{ styleConfig.text['button'] }}">{{"分诊派单"}}</text>
      </button>
   </view>
</view>


回答关注问题邀请回答
收藏
登录 后发表内容