Skip to content

reactivityTransform 功能(已废弃)

警告

该方法已在 Ray Template4.5.0 版本彻底移除,不再支持。

vue3 的响应式函数后,每一次修改或者访问 ref 响应式数据时,需要进行显示的 .value 调用,显得及其繁琐。所以尤大大团队提出了该 SFC 意在减轻开发者的心智负担。

提示

但是,实际上这个试验性功能很多问题,并且最终被遗弃。具体被舍弃原因可以查看原文

使用方法

vue
<script setup>
let count = $ref(0)

console.log(count)

function increment() {
  count++
}
</script>

<template>
  <button @click="increment">{{ count }}</button>
</template>

经过编译后,会被转换为这样:

js
import { ref } from 'vue'

let count = ref(0)

console.log(count.value)

function increment() {
  count.value++
}

具体这里就不做赘述了,有兴趣可以去查看官网地址

api

  • ref => $ref
  • computed => $computed
  • shallowRef => $shallowRef
  • customRef => $customRef
  • toRef => $toRef

Released under the MIT License.