关于前端:ECMAScript-中-的export-转发

32次阅读

共计 503 个字符,预计需要花费 2 分钟才能阅读完成。

// ----- head.js -----

export const eye = '纯净的'
export const nose = '高耸的'

export default {
    eye,
    nose
}





// ----- index.js -----

// 想实现
// import {eye, nose} from './head.js'
// export {eye, nose}

export {eye, nose} from './head.js'


// 想改名

export {eye as pureEye, nose as loftyNose} from './head.js'


// 把 head.js 所有的 (default/eye/nose) 导出

export * from './head.js'
export * as headObj from './head.js'
// index.html

<body>
    
    // 动态加载,前面无奈拿到 js 里的变量
    <script type="module" src="./index.js"></script>

    // 要想和数据互动
    <script type="module">
    import index from './index.js'
    // do someting ...

  </script>

</body>

正文完
 0