[英]How to import mulitple variables or list from another component in React JS?
I have a Profile.js component which uses some list.我有一个 Profile.js 组件,它使用了一些列表。 The list is two big so I want to shift the list to a different LabelValue.js component and import it in Profile.js.该列表很大,因此我想将列表转移到不同的 LabelValue.js 组件并将其导入 Profile.js。 But I'm not able to do so.但我不能这样做。 Kindly depict the right way to do the import and export.请描述正确的进出口方式。
In LabelValue.js在 LabelValue.js 中
const bloodGroups = [
{ label: "Choose", value: "" },
{ label: "A+", value: "A+" },
{ label: "B+", value: "B+" },
{ label: "AB+", value: "AB+" },
{ label: "O+", value: "O+" },
{ label: "O-", value: "O-" },
{ label: "A-", value: "A-" },
{ label: "B-", value: "B-" },
{ label: "AB-", value: "AB-" },
];
const genders = [
{ label: "Choose", value: "" },
{ label: "Male", value: "Male" },
{ label: "Female", value: "Female" },
{ label: "Others", value: "Others" },
];
export default { genders, bloodGroups };
In Profile.js在 Profile.js 中
import { bloodGroups, genders } from ".path/to/LabelValue.js"
The Error错误
./src/Pages/Profile.js
Attempted import error: 'bloodGroups' is not exported from '../LabelValue'.
Use利用
export { genders, bloodGrousps };
NOT不是
export default { genders, bloodGrousps };
Default is for single value默认为单个值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.