TypeScript

237 阅读1分钟
  • 微软推出的

    typescript>ES6>javascript 运行的时候,ts 编译成javascript 静态类型的语言 强类型 遵循ES6 编译器严谨的语法检查 vue,react,angular,小程序都推荐用ts ts默认文件后缀名.ts

  • Vue3+TS+setup+volar

定义变量

- 字符串

  1. const str = ref("abc")
  2. const str = ref("abc")根据值类型自动判断改类型变量是什么

数字

const count = ref<number>(10)
const count = ref(10)

布尔值

const flag = ref<boolen>(true)
const flag = ref(true)

函数

function add(n1:string,n2:number):void{
}

接口

定义接口
interface Iuser = {
name:string,
age:number|string
}
const user = reactive<Iuser>({
    name:"mumu",
   age:18
})

在setup中获取props

import{defineProps} from 'vue'
intervace Iprops = {min:number,max:number}
const props =defineProps<Iprops>()