为什么在导入时出现定义变量但未使用该变量的错误?它们在同一文件夹中。我正在使用它。感谢您的输入!
错误
'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
}
trapi-helpers.js
function componentName(currentName) {
if (currentName && currentName.indexOf('.')) {
return currentName.replace('.', '-')
}
}
export {
componentName
}
您的函数使用相同名称的参数隐藏了导入。因此,从不使用它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句