简体   繁体   English

我尝试从 react native 中的另一个 js 文件导入 JS 文件中的数组数据,并尝试检查 react native 中的数组长度

[英]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

在此处输入图像描述

TypeError: undefined is not an object (evaluating '_kurals.default.length') i got this error. TypeError: undefined is not an object(评估'_kurals.default.length')我收到了这个错误。 在此处输入图像描述

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

If you want to import it as a default, like you did with import kurals from './kurals';如果您想将其作为默认值导入,就像您对import kurals from './kurals'; , then it must be exported as default: ,那么它必须默认导出:

export default [];

Since you exported it with export const kurals = [];由于您使用export const kurals = [];导出了它then it's a property of the exported object and you need to destructure it:那么它是导出的 object 的属性,您需要对其进行解构:

import { kurals } from './kurals';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM