【问题标题】:Import in js file becomes 'myProperty' is defined but never used在 js 文件中导入成为 'myProperty' 已定义但从未使用过
【发布时间】:2021-04-05 04:18:22
【问题描述】:

为什么在导入时会收到此变量已定义但未使用的错误?它们在同一个文件夹中。我正在使用它。感谢您的意见!

错误

'componentName' 已定义但从未使用过。


动态组件数据映射.js

import { componentName } from './strapi-helpers.js'

function mapData(response, componentName) {
  const componentList = response.reduce(function(matchedComponents, component) {
    if (component.__component === componentName) {
      component.__component = componentName(component.__component)

      matchedComponents.push(component)
    }

    return matchedComponents
  }, [])

  return componentList
}

export {
  mapData
}


strapi-helpers.js

function componentName(currentName) {
  if (currentName && currentName.indexOf('.')) {
    return currentName.replace('.', '-')
  }
}

export {
  componentName
}

【问题讨论】:

  • 您的函数使用同名参数隐藏导入。因此它从未被使用过。
  • 可能是因为该文件中没有调用mapData() 函数? componentName 参数就是这样。在有人调用它之前,它与导入无关。

标签: javascript vue.js ecmascript-6 es6-modules


【解决方案1】:

您的函数使用同名参数隐藏导入。因此它从未被使用过。

【讨论】:

    猜你喜欢
    • 2022-06-20
    • 2020-03-17
    • 2022-11-25
    • 1970-01-01
    • 2017-02-03
    • 1970-01-01
    • 2019-08-16
    • 2023-01-07
    • 2021-03-20
    相关资源
    最近更新 更多