梗概:

  • ref 函数将没有响应式的基本数据类型转变为reflmpl
  • 如果用于reactive的话没有效果
  • child::toRef与ref的区别

语法:

let test = ref<值的类型>(值或响应式变量)

1. 返回值:

  1. 返回响应式引用

原理

child::ref原理

实例:

import { ref } from 'vue'
 
const counter = ref(0)
 
console.log(counter) // { value: 0 }
console.log(counter.value) // 0
 
counter.value++
console.log(counter.value) // 1