newMap映射关系

映射关系

const typeFn = (type:number) => {
  const labelMap = {
    1:'蔡',
    2:'陈',
    3:'范',
  }
  let newValue= (labelMap as any)[type] 
  return newValue
}

const otherFn = new Map([
  [1,'蔡'],
  [2,'陈'],
  [3,'范']
])

onMounted(()=>{
  
})
function getReason(reasonNumber: number): string {
    const reasons: Record string> = {
        1: function() {
            return "蔡"
        },
        2: function() {
            return "陈"
        },
        3: function() {
            return "范"
        }
    }

    if (reasons[reasonNumber]) {
      console.log('22');
    } else {
      // Either handle the error, or return a default...
      throw new Error('')
    }
}

你可能感兴趣的:(前端,javascript,开发语言)