【发布时间】: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