In the vue project, after import introduces the same file twice, the second time will be undefined

index.js
import a from"@ / views/apidocument/test/a"
console.info (a); / / has value

a.js
import c from". / c"
console.info ("bbbbbbbb",c); / / valuable
const a = {

created(){
    /* let cc = new c();
    cc.name="aaa"
    console.info(cc.name); */
    // c.name = "aaa"
}

}
export default a

c.js
import a from". / a"
console.info ("cccccccccc", a); / / undefined Why undefined?
const c = {

name: "ccc"

}
export default function () {

return {...c}

}

Nov.15,2021

your circular dependency of the es6 module causes
when the c module executes to console.info ('cccccccccc', a) ), the a variable in the a module has not yet been assigned, so the output is undefined
you can set a delay to try, it should have a value

es6 module mechanism can be found in
in-depth understanding of ES6 module mechanism
cyclic loading of JavaScript module

Menu