Summary of TS variable definitions

1. Common file: scr/interface/common.ts

       define a public interface

  export interface option {
        value:any, //任意类型
        label:string,
        id:string | number  //数字或字符串类型
        name?:string        // ?-非必填
        [propname:string]:any   //key值为string类型的,任意类型

  }

.vue file introduction: import { option } '@/interface/common'

2. The .vue file is defined separately

interface option {
        value:any, //任意类型
        label:string,
        id:string | number  //数字或字符串类型
        name?:string        // ?-非必填
        [propname:string]:any   //key值为string类型的,任意类型

  }

3. Define the field type:

3.1, ref/reactive binding data definition

const  id=ref<string>('')

const  status=ref<string | number>('')

const obj=ref<option>({})

const arr=ref<option[]>([])

const state = reactive({
     list: [] as Array<number>   
})

3.2. For loop definition:

arr.forEach((item:option)=>{
    ...
})

3.3, let definition

let list:option[]=[]

3.4. Definition of function passing value

const fn=(e:arry<option>,id:string,obj:option)=>{
    ...
}

おすすめ

転載: blog.csdn.net/weixin_38961329/article/details/127572804