【问题标题】:i try to import a array data in JS file from another js file in react native , and i try to check the length of the array in react native我尝试从 react native 中的另一个 js 文件导入 JS 文件中的数组数据,并尝试在 react native 中检查数组的长度
【发布时间】:2022-01-14 13:25:21
【问题描述】:

TypeError: undefined is not an object (evalating '_kurals.default.length') 我得到了这个错误。

export const kurals =[];
import kurals from './kurals';
 console.log(`data1.length`, kurals.length);

【问题讨论】:

  • 你能告诉我们你的代码吗
  • _kurals.default 似乎未定义。
  • export const kurals =[];从 './kurals' 导入 kurals; console.log(data1.length, kurals.length);

标签: javascript arrays reactjs json react-native


【解决方案1】:

如果您想将其作为默认值导入,就像对 import kurals from './kurals'; 所做的那样,则必须将其导出为默认值:

export default [];

由于您使用export const kurals = []; 导出它,因此它是导出对象的属性,您需要对其进行解构:

import { kurals } from './kurals';

【讨论】:

    猜你喜欢
    • 2021-04-26
    • 2022-11-28
    • 1970-01-01
    • 2016-11-23
    • 1970-01-01
    • 2017-05-29
    • 1970-01-01
    • 2017-03-10
    • 1970-01-01
    相关资源
    最近更新 更多