ES6 export all values from object

前端 未结 9 1801
梦谈多话
梦谈多话 2020-11-28 07:32

Say I have a module (./my-module.js) that has an object which should be its return value:

let values = { a: 1, b: 2, c: 3 }

// \"export values\         


        
9条回答
  •  天涯浪人
    2020-11-28 08:27

    I just had need to do this for a config file.

    var config = {
        x: "CHANGE_ME",
        y: "CHANGE_ME",
        z: "CHANGE_ME"
    }
    
    export default config;
    

    You can do it like this

    import { default as config } from "./config";
    
    console.log(config.x); // CHANGE_ME
    

    This is using Typescript mind you.

提交回复
热议问题