typescript(TS)由微软推出的
-
typescript>ES6>javascript
-
运行的时候,ts 编译成 javascript
-
静态类型的语言:强类型、遵循ES6、编译器严谨的语法检查
-
vue、react、angular、小程序都推荐用ts, ts默认文件后缀名.ts
Vue3+TS+setup+volar
TS语法格式:
- <script lang="ts" setup> </script>
定义变量:
1、字符串
const str = ref<string>("abc")
const str = ref("abc")
根据值类型自动判断改类型变量是什么
2、数字
const count = ref<number>(10)
const count = ref(10)
3、布尔值
const flag = ref<boolen>(true)
const flag = ref(true)
4、函数
function add(n1:string,n2:number):void{
}
5、接口
定义接口:
interface Iuser = {
name:string,
age:number|string
}
const user = reactive<Iuser>({
name:"shangwu",
age:18
})
在setup中获取props
import{defineProps} from 'vue'
interface Iprops = {min:number,max:number}
const props =defineProps<Iprops>()
TypeScript是由微软推出的静态类型语言,强类型、遵循ES6并提供严谨的语法检查。在Vue3、React、Angular和小程序中被广泛推荐使用。本文将介绍Vue3+TS+setup+volar的配置,并详细讲解如何定义不同类型变量,包括字符串、数字、布尔值、函数和接口。
859

被折叠的 条评论
为什么被折叠?



