1 |
- export default setWatcher;function setWatcher(e){const{data:t,watch:o}=e;if(!t||!o)return console.log("找不到watch或data");Object.keys(o).forEach((n=>{const a=n.split("."),c=a.length;let f=t;for(let e=0;e<c-1;e++)f=t[a[e]];observe({obj:f,key:a[c-1],fn:o[n].handle||o[n],page:e,deep:o[n].deep})}))}function observe({obj:e,key:t,fn:o,page:n,deep:a}){let c=e[t];a&&null!==c&&"object"==typeof c&&Object.keys(c).forEach((e=>{observe({obj:c,key:e,fn:o,page:n,deep:a})})),Object.defineProperty(e,t,{set(f){o instanceof Function&&o.call(n,f,c,t),c=f,a&&observe({obj:e,key:t,fn:o,page:n,deep:a})},get:()=>c})}
|