ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 标准 API:observe 绑定监听,自定义配置项。回调函数的第一个参数为 MutationRecord[]。 > `observe(target, callback, option)` - target - 描述:需要被监听的节点 - 类型:`String`/`Element`/`Node` - callback - 描述:监听到变化时执行的回调函数 - 类型:`(mutations: MutationRecord[], observer: MutationObserver) => void` - option - 描述:监听配置项 - 类型:[`MutationObserverInit`](https://developer.mozilla.org/zh-CN/docs/Web/API/MutationObserverInit) ## 变种 API:eobserve 绑定监听,自定义配置项。回调函数的第一个参数为 MutationRecord。 > `eobserve(target, eachcall, option)` - target - 描述:需要被监听的节点 - 类型:`string`/`Element`/`Node` - eachcall - 描述:监听到变化时执行的回调函数 - 类型:`(mutation: MutationRecord, observer: MutationObserver) => void` - option - 描述:监听配置项 - 类型:[`MutationObserverInit`](https://developer.mozilla.org/zh-CN/docs/Web/API/MutationObserverInit) ## DEMO ```js import { observe, eobserve } from "m-observer" const option = { subtree: true, childList: true } observe('#demo1' (mutations) => { for (let mutation of mutaitons) { // do something } }, option) eobserve('#demo2', (mutation) => { // do something }, option) ```