// vite.config.js
export default {
plugins: [
vue({
reactivityTransform: true
})
]
}
import { $ref } from 'vue/macros'ref => $ref,不需要再使用var.value,而是直接使用varprops.x。fn($ref)编译结果会是fn($ref.value)。而函数内期望是传入一个$ref$$(ref) 包装,效果是去掉.value。return { x, y } => return { x: x.value, y: y.value }return $$({ x, y })const { prop } = defineProps({a: 1}); fn($$prop);,解析成toRef()包裹。 (1)definedProxy (2)proxy-reactive (3)value setter-ref
缺点 数组和属性删除等拦截不了 不兼容ie11 只拦截了value
优点 兼容 全拦截 实现简单
// 在同一个对象上调用 reactive() 会返回相同的代理
console.log(reactive(raw) === proxy) // true
// 在一个代理上调用 reactive() 会返回它自己
console.log(reactive(proxy) === proxy) // true
nextTick()