为什么我能够这样做:
export const state = {};
但我不能这样做:
const state = {}
export state; // 'Declaration or statement expected' error
答案 0 :(得分:2)
所以你有2路使用导出: 你已经完成了这个:
export const state = /*whatever you want*/
这一个:
const state = /*whatever you want*/
export { state };
然后你可以用它:
import { state } from './otherFileName'
<强>语法强>
export { name1, name2, …, nameN }; export { variable1 as name1, variable2 as name2, …, nameN }; export let name1, name2, …, nameN; // also var, function export let name1 = …, name2 = …, …, nameN; // also var, const