Loading... 进行标准化编程的时候,我们需要对数据类型进行限制时,就要使用到type `/types/index.ts` ```ts export interface PersonInter{ id:string, name:string, age:number } export type persons = PersonInter[] ``` `personInter`是单个,`persons`为数组 `test.vue` ```vue <template> <div class="person"> </div> </template> <script lang="ts" setup name="test"> import {type PersonInter,type persons} from '@/types' let person:PersonInter={ id:'abc', name:'yanlin', age:123 } let personList:persons = [ {id:'abc1',name:'yanlin',age:123}, {id:'abc2',name:'yanlin123',age:1}, {id:'abc3',name:'yanlin456',age:2} ] </script> <style> </style> ``` 在定义名字后加入:就是指定类型。 最后修改:2025 年 02 月 02 日 © 允许规范转载 赞 不用打赏哦!