TODO Vue typescript forEach的bug,需要再核實

forEach 一個string[],只有最後一個匹配條件有效,其它條件無效。

所以,只能替換成普通的for循環。

复制代码
  console.log(taskList)
    // for (const _task of taskList.value) {
    //   if (_task == 'invoiceSendEmail') {
    //     form.value.invoiceSendEmail = true
    //   } else if (_task == 'invoicePrint') {
    //     form.value.invoicePrint = true
    //   } else if (_task == 'statementSendEmail') {
    //     form.value.statementSendEmail = true
    //   } else if (_task == 'statementPrint') {
    //     form.value.statementPrint = true
    //   } else if (_task == 'courierPrint') {
    //     form.value.courierPrint = true
    //   }
    // }

    taskList.value.forEach((task: string) => {
      let _task = ''
      _task = task
      form.value.invoiceSendEmail = false
      form.value.invoicePrint = false
      form.value.statementSendEmail = false
      form.value.statementPrint = false
      form.value.courierPrint = false

      if (_task == 'invoiceSendEmail') {
        form.value.invoiceSendEmail = true
      }
      if (_task == 'invoicePrint') {
        form.value.invoicePrint = true
      }
      if (_task == 'statementSendEmail') {
        form.value.statementSendEmail = true
      }
      if (_task == 'statementPrint') {
        form.value.statementPrint = true
      }
      if (_task == 'courierPrint') {
        form.value.courierPrint = true
      }
    })

    console.log(form)

以及通過forEach 返回時,沒有返回任何内容

必須重新賦值,才能返回 let dic = {} as DictionaryItem

复制代码
export const getDictionaryFromClient = (code: string, value: string) => {
  let dic = {} as DictionaryItem

  sys_dic_client.value.forEach((_dic: DictionaryItem) => {
    if (_dic.code == code && _dic.value == value) {
      dic = _dic
    }
  })
  return dic
}
相关推荐
会豪15 小时前
Electron-Vite (一)快速构建桌面应用
前端
中微子15 小时前
React 执行阶段与渲染机制详解(基于 React 18+ 官方文档)
前端
唐某人丶15 小时前
教你如何用 JS 实现 Agent 系统(2)—— 开发 ReAct 版本的“深度搜索”
前端·人工智能·aigc
中微子15 小时前
深入剖析 useState产生的 setState的完整执行流程
前端
遂心_15 小时前
JavaScript 函数参数传递机制:一道经典面试题解析
前端·javascript
小徐_233315 小时前
uni-app vue3 也能使用 Echarts?Wot Starter 是这样做的!
前端·uni-app·echarts
RoyLin15 小时前
TypeScript设计模式:适配器模式
前端·后端·node.js
遂心_16 小时前
深入理解 React Hook:useEffect 完全指南
前端·javascript·react.js
Moonbit16 小时前
MoonBit 正式加入 WebAssembly Component Model 官方文档 !
前端·后端·编程语言
龙在天16 小时前
ts中的函数重载
前端