VUE如何在另一个函数中调用另一个函数运算后的结果

首先在最外层声明一个公用的变量/数组

let arr = ref([])

 这是第一个函数,示例为将excel表格类文件 转换为json格式数组,并且结果为 result

  async function onChange(e) {
    const file = e.target.files[0]
    const reader = new FileReader()
    reader.readAsBinaryString(file)
    reader.onload = function (e) {
      const data = e.target.result
      const zzexcel = read(data, {
        type: 'binary',
      })
      console.log('zzexcel', zzexcel)
      const result = []
      for (let i = 0; i < zzexcel.SheetNames.length; i++) {
        const newData = utils.sheet_to_json(zzexcel.Sheets[zzexcel.SheetNames[i]], {
          range: 3,
          header: [
            'id',
            'oneOrgName',
            'twoOrgName',
            'positionName',
            'unitName',
            'deviceName',
            'professionName',
            'partName',
            'encoding',
            'specification',
            'manufacturer',
            'useTime',
            'peopleNum',
            'level',
            'userCode',
          ],
          defval: '',
        })
        result.push(...newData );
        arr.value = result
      }
    }
  }

通过最后一行代码可以看出将声明的 arr 赋值通过第一个函数运算出的结果result

接下来就可以在下面函数中继续使用result的结果了,下面函数中的arr.value就为经过上面函数运算的结果result数组

function sumbitUpload() {
    setModalProps({ loading: true })
    let array = JSON.parse(
      JSON.stringify(arr.value)
        .replace(/机械/g, '1')
        .replace(/电气/g, '2')
        .replace(/仪表/g, '3')
        .replace(/液压/g, '4')
        .replace(/自动化/g, '5')
        .replace(/信息化/g, '6'),
    )
    console.log(array)
    Import(array).then((res) => {
      const taskdata = res.Data
      ReadJobProcess(taskdata).then((res) => {
        const process = res.Content
      })
      ReadJobReport(taskdata).then((res) => {
        const report = res.Content
      })
    })
    createSuccessModal({ content: '操作完成' })
    closeModal()
  }

分享完毕,感谢观看!!!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值