在 js 文件中导入变为 'myProperty' is defined but never used
Import in js file becomes 'myProperty' is defined but never used
为什么在执行导入时会出现变量已定义但未使用的错误?它们在同一个文件夹中。我正在使用它。感谢输入!
错误
'componentName' is defined but never used.
动态组件数据-mapping.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
}
您的函数使用同名参数隐藏导入。因此从未使用过。
为什么在执行导入时会出现变量已定义但未使用的错误?它们在同一个文件夹中。我正在使用它。感谢输入!
错误
'componentName' is defined but never used.
动态组件数据-mapping.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
}
您的函数使用同名参数隐藏导入。因此从未使用过。