vue3的reactive与ref区别是什么?
网友回复
Vue3 中 reactive 和 ref 的区别主要在于:
接收数据类型不同
ref 用来处理基本类型数据,如:字符串、数值、布尔值等 reactive 用来处理对象(Object) 和 数组(Array) 示例代码:// 基础类型使用ref const name = ref('张三') // 对象或数组使用reactive const user = reactive({ name: '李四', age: 20 })
原理不同
ref 用来包装基本类型数据,内部通过对象存储值并返回代理对象reactive 通过 Proxy 实现对对象属性的响应式追...
点击查看剩余70%