vue3的ref变量声明类型注解

1使用默认类型
const str = ref("")
str.value = 'tom

  

2 //使用泛型
const num = ref<number>() 
num.value = 20

 

type GoodType = {
  id: string
  name: string
  price: number
}
const goodList = ref<GoodType[]>([])

  

3 使用类型断言
type GoodType = {
  id: string
  name: string
  price: number
}
const goodLists = ref([] as GoodType[])

 

posted @ 2024-06-19 20:19  light丶  阅读(163)  评论(0)    收藏  举报