头像

你好,我是小小卒

欢迎来到我的科技空间

使用 Proxy 实现响应式数据绑定

使用 Proxy 实现响应式数据绑定

const state = new Proxy(
  { count: 0 },
  {
    set(target, key, value) {
      target[key] = value;
      console.log(`state.${key} = ${value}`);
      document.querySelector('#count').textContent = value;
      return true;
    },
  }
);

document.querySelector('#inc').onclick = () => state.count++;

示例:
录屏2025-07-21-16.46.54

posted @ 2025-07-18 10:07  node_mini  阅读(10)  评论(0)    收藏  举报