Skip to content

lc-cn/obj-observer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

obj-observer

js/ts 对象监听

  1. 安装依赖
npm install obj-observer
# 或 npm i
  1. 在需要的地方引入watch方法,监听对象或数组的变化
import {ref,watch} from 'obj-observer'
const obj=ref({test:123})
const dispose=watch(obj,
    (value,oldValue)=>{
        console.log('trigger change',value,oldValue)
    })
obj.test='hi world' //'trigger change' {test:'hello world'} {test:'hi world'}