# 一、定义 ref 类型的三种方式
- 自动推断
<script setup>
import { ref } from 'vue'
const num = ref(0)
</script>
2. 显示定义类型(需要导入 Ref)
代码语言:javascript复制<script setup>
import { ref, Ref } from 'vue'
const str: Ref<string> = ref('str')
</script>3. 直接在 ref 后面加上泛型
<script setup>
import { ref } from 'vue'
const bool = ref<boolean>(true)
</script># 总结-写在最后
说明
ref 和 reactive 定义类型是一样的


