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/文件夹下去找

  • 相关阅读:
    java-多态
    java-继承
    java-访问修饰符
    mysql基础入门
    子查询
    多表查询
    mysql表(多对多)
    myslql主外键约束
    Sql语句分类
    Redis的一些介绍
  • 原文地址:https://www.cnblogs.com/xiaoliwang/p/8577715.html
Copyright © 2011-2022 走看看