zoukankan      html  css  js  c++  java
  • ES6 模块导入import 导出export 和module.export

    ES6中新增了模块的导入和导出功能

    在实际过程中可以使用 import 和 export 对模块进行导入和导出操作,具体如下

    1. 名字导入/导出  (导入名字必须与导出的一致,导入时需要用花括号)

    //------ lib.js ------
    export const sqrt = Math.sqrt;
    export function square(x) {
        return x * x;
    }
    export function add (x, y) {
        return x + y;
    }

    2 . 导入时也可以用 * ,导入整个文件

    //------ main.js ------
    import * as lib from lib.js
    console.log(lib.sqrt)
    console.log(lib.add)

    3. 默认导出,每个模块可以有一个默认导出,这样导入时的名字可以与导出不一致

    /* Store实例 */
    export default new Vuex.Store({
        state,
        getters,
        actions,
        mutations
    })
    import store from './store/'

     在 import 的时候 如果不使用相对路径或者绝对路径,node默认会去node_modules/文件夹下去找

  • 相关阅读:
    安装pgsql
    ln软连接
    vsftp上传失败
    redis配置systemctl
    jmeter 录制排除模式
    数据库基本操作
    按日期排序
    angularjs的cache
    angularjs路由传递参数
    angularjs路由相关知识
  • 原文地址:https://www.cnblogs.com/xiaoliwang/p/8577715.html
Copyright © 2011-2022 走看看