首页 > 其他分享 >前端学习-vue视频学习008-TS中的接口\泛型\自定义类型

前端学习-vue视频学习008-TS中的接口\泛型\自定义类型

时间:2024-03-18 21:59:33浏览次数:18  
标签:vue 20 name 自定义 personInter gender age TS type

尚硅谷视频链接

使用ts定义,可限制参数的类型

新建ts文件

// 定义接口限制对象属性
export interface personInter {
    name:string,
    age:number,
    gender:string
}

// 使用泛型
// export type personArr = Array<personInter>
// 另一种写法
export type personArr = personInter[]

引入并使用

<template>
    <div class="person">
        ???
    </div>
</template>

<script lang="ts" setup name="Person">
    import {type personInter,type personArr} from '@/types'
    let person1:personInter = {name:'111',age:20,gender:'F'}
    let person2:Array<personInter> = [
        {name:'111',age:20,gender:'F'},
        {name:'222',age:20,gender:'F'},
        {name:'333',age:20,gender:'F'}
    ]
    let person3:personArr = [
        {name:'111',age:20,gender:'F'},
        {name:'222',age:20,gender:'F'},
        {name:'333',age:20,gender:'F'}
    ]
</script>

<style scoped>
    .person {
        background-color: skyblue;
        box-shadow: 0 0 10px;
        border-radius: 10px;
        padding: 20px;
    }
    
    button {
        margin : 0 5px;
    }

    li {
        font-size : 20px;
    }
</style>

标签:vue,20,name,自定义,personInter,gender,age,TS,type
From: https://www.cnblogs.com/ayubene/p/18081266

相关文章

  • 为 PyTorch 层指定自定义名称
    参考这个问答,有两种方法。第一种,在定义nn.Sequential时传入OrderedDict类型变量。importcollectionsimporttorchmodel=torch.nn.Sequential(collections.OrderedDict([("conv1",torch.nn.Conv2d(1,20,5)),("relu1",tor......
  • JavaScript学习笔记7: 对象 - 自定义对象&JSON
    JS对象-自定义对象&JSON自定义对象类似java的类Json的所有属性(key)需要用双引号包围,本质是字符串<script>    varuser={    name:"tom",    age:10,    gender:"male",    //eat:function(){}    //可以简写为    eat(){//自......
  • Vue3+El-Dialog实现弹框
    1.子组件childComponents.vue<template><divclass="hello">{{`在学习VUE3`}}</div><el-dialogtitle="提示"v-model="dialogVisble"width="30%"><span>这是一段信息</span><templat......
  • Eclipse设定自定义格式化(解决java格式化注释中参数挤在一行的问题)
    1.问题在java默认的格式化中,对于注释这一块的格式化,当有多个参数Param,都是挤在一起的,导致十分不美观,我们这时就需要自定义java格式化2.解决2.1找到Java>CodeStyle>Formatter2.2由于Eclipse默认的格式化文件不可以修改,这里我们基于其选择新建一个自定义格式化文件2......
  • 数据可视化-ECharts Html项目实战(3)
    在之前的文章中,我们学习了如何创建堆积折线图,饼图以及较难的瀑布图并更改图标标题。想了解的朋友可以查看这篇文章。同时,希望我的文章能帮助到你,如果觉得我的文章写的不错,请留下你宝贵的点赞,谢谢。数据可视化-EChartsHtml项目实战(2)-CSDN博客文章浏览阅读1.2k次,点赞33次,收藏16......
  • Java毕业设计 基于springboot vue招聘网站 招聘系统
    Java毕业设计基于springbootvue招聘网站招聘系统springbootvue招聘网站招聘系统功能介绍用户:登录个人信息简历信息查看招聘信息企业:登录企业信息管理发布招聘信息职位招聘信息管理简历信息管理管理员:注册登录管理员管理用户管理企业管理简历信息管理......
  • vue2 nuxt打包时间超过1小时异常
    使用 npmrungenerate打包时提示:Thecommand'nuxtgenerate'finishedbutdidnotexitafter5s││ThisismostlikelynotcausedbyabuginNuxt││Makesuretocleanupalltimersandlistenersyouoryour││plugins/modu......
  • vue element-ui prop 同时校验两个输入框都不能为空
    <el-row><el-col:span="24"><el-form-itemlabel="故障阈值:"class="a_row":prop="addForm.thresholdFaultMin.length==0?'thresholdFaultMin':'thresholdFaultMax&#......
  • Vue+OpenLayers7入门到实战:OpenLayers7创建自定义鹰眼控件,自定义鹰眼控件样式,调整鹰眼
    返回《Vue+OpenLayers7》专栏目录:Vue+OpenLayers7入门到实战前言本章介绍如何使用OpenLayers7在地图上创建自定义鹰眼控件,自定义鹰眼控件样式,调整鹰眼控件位置、大小、文字和按钮等样式。二、依赖和使用"ol":"7.5.2"使用npm安装依赖[email protected]使用Y......
  • OpenLayers6实战,OpenLayers创建自定义鹰眼控件,自定义鹰眼控件样式,调整鹰眼控件位置、
    专栏目录:OpenLayers实战进阶专栏目录前言本章讲解OpenLayers6如何创建自定义鹰眼控件,自定义鹰眼控件样式,调整鹰眼控件位置、大小和文字和按钮等自定义样式的功能。二、依赖和使用"ol":"^6.15.1"使用npm安装依赖[email protected]使用Yarn安装依赖yarn......