(三)Ref 类型定义
2022年11月30日
ref
类型的三种方式
一、定义 - 自动推断
<script setup>
import { ref } from 'vue'
const num = ref(0)
</script>
- 显示定义类型(需要导入 Ref)
<script setup>
import { ref, Ref } from 'vue'
const str: Ref<string> = ref('str')
</script>
- 直接在
ref
后面加上泛型
<script setup>
import { ref } from 'vue'
const bool = ref<boolean>(true)
</script>
总结-写在最后
说明
ref
和 reactive
定义类型是一样的
Loading...