Javascript 如何从React JS中的另一个组件导入多个变量或列表?
我有一个Profile.js组件,它使用一些列表。这个列表是两个大的列表,所以我想将列表转移到另一个LabelValue.js组件,并将其导入到Profile.js中。但我不能这么做。请描述正确的进出口方式 在LabelValue.js中Javascript 如何从React JS中的另一个组件导入多个变量或列表?,javascript,reactjs,import,export,Javascript,Reactjs,Import,Export,我有一个Profile.js组件,它使用一些列表。这个列表是两个大的列表,所以我想将列表转移到另一个LabelValue.js组件,并将其导入到Profile.js中。但我不能这么做。请描述正确的进出口方式 在LabelValue.js中 const bloodGroups = [ { label: "Choose", value: "" }, { label: "A+", value: "A+" },
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 };
import { bloodGroups, genders } from ".path/to/LabelValue.js"
在Profile.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 };
import { bloodGroups, genders } from ".path/to/LabelValue.js"
错误
./src/Pages/Profile.js
Attempted import error: 'bloodGroups' is not exported from '../LabelValue'.
使用
不是
默认为
bloodgroups
中的单个值输入错误,这是stackoveflow中的输入错误。我已经更新了。它在我的代码中写得很正确。