Change the value of imported variable in ES6

前端 未结 2 841
旧巷少年郎
旧巷少年郎 2020-12-30 21:12

I\'m using ES6 modules and am importing a variable from moduleA into moduleB:

//moduleA.js
let a = 5;
let b;

export { a, b };

//m         


        
2条回答
  •  执念已碎
    2020-12-30 21:45

    You can use an object instead of variables, like this the reference doesn't change :

    //moduleA.js
    let object = {
        a: 5,
    };
    
    export { object };
    
    //moduleB.js
    import { object } from './moduleA'
    
    object.a = 6;
    object.b = 1;
    

提交回复
热议问题