HomeDocs
跳到主要内容

Observe 观测容器

简介

观测容器。可用于观测容器内容在页面中的显示情况。

属性说明

属性名类型默认值必填说明
stateStringTRUE观测开关,用于开启或者关闭观测
targetQuerySelectorString观测容器本身指定观测 DOM,参数参考 querySelector,默认是观测容器本身
optionsObject{root: null, threshold:0}IntersectionObserver 的 option 属性,用于控制观察者的回调函数的被调用时的环境
changeEventHandle根据传入的 options,当观测元素可视区域符合 options 的配置是,会触发此事件

示例

<scroll-view
class="scroll-container"
:scroll-y="true"
:scroll-top="scrollTop"
:refresher-enabled="refresherEnabled"
:refresh-state="refreshState"
bind:refresh="pulldownRefresh"
bind:scrolltolower="scrollToLower"
>
<observe
bind:change="handleListVisibleChange"
s-for="(item, index) in recommendList"
:key="item.id"
:state="item.state"
:options="observeOption"
:data-index="index"
>
<view class="list-item__gap"></view>
<component
:is="item.componentName"
class="list-item forbidselect"
:data="item"
bindopen="handleNavigateToOutside"
bindshare="handleShare"
></component>
</observe>
<view
class="hasmore-wrap flex-center-center"
s-if="hasMore && network && recommendList.length"
>
<loading></loading>
</view>
</scroll-view>
Page({
...
handleListVisibleChange (data) {
console.log(data)
/* {
dataset,
value: {
boundingClientRect,
intersectionRatio,
intersectionRect,
isIntersecting,
rootBounds,
time,
},
}
*/
}
})
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.