vue3+ts 实现枚举

首先 index.ts 中定义枚举

export const fruit=  [
  {
    key:1,
    name:'苹果',
  },
  {
    key:11,
    name:'草莓'
  },
  {
      key:5,
      name:'香蕉',
    },
    {
        key:51,
        name:'葡萄',
      },
  {
    key:6,
    name:'橙子'
  },
    {
      key:7,
      name:'哈密瓜'
    },
    {
      key:10,
      name:'西瓜'
    },
]; 

接口返给的数据是一个对象

feeMap{
1:200,
2:100
}
const demand = reactive([])
fruit.forEach(item=>{ 
      for (let key in  feeMap.value) {
        if (item.key == key as any) {
          item.value = feeMap.value[key]
        }else if(item.value == "" || item.value== undefined){
          item.value = "--"
        }else{
          
        }
      }
    })


  demand.push(...fruit)

你可能感兴趣的:(前端,javascript,vue.js)