vue3的数据响应式系统
乔文飞 Lv8

Vue2.0的数据监听

Object.defineProperty

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const object1 = {};

Object.defineProperty(object1, 'property1', {
value: 42,
writable: false,
get(){},
set(newValue) { bValue = newValue; },
enumerable : true,
configurable : true
});

object1.property1 = 77;
// throws an error in strict mode

console.log(object1.property1);
// expected output: 42

Vue3.0的数据响应式系统

proxy get\set

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// 引用vue-next(3)源码中'packages/reactivity/dist/reactivity.global.js'

const {reactive, effect} = VueObserver;
// reactive: 把数据处理成为响应式数据
// effect:
// 1.首先会执行一次对应的监听函数
// 2.修改对应监听函数内使用的响应式数据,对应的监听函数就会立即执行,重新执行的过程就会获取新的数据
const yideng = {count: 0};
const state = reactive(yideng);
const fn = ()=>{
const count = state.count;
const.log('当前的count', count)
//render(count) 如果在这触发render渲染
}

effect(fn)
  • 本文标题:vue3的数据响应式系统
  • 本文作者:乔文飞
  • 创建时间:2021-03-19 15:54:57
  • 本文链接:http://www.feidom.com/2021/03/19/vue3的数据响应式系统/
  • 版权声明:本博客所有文章为作者学习笔记,有转载其他前端大佬的文章。转载时请注明出处。