Node.js使用不带模块名称的导入

时间:2019-03-03 07:20:32

标签: javascript node.js import

utilities / calculator.js

function results() {
    var name = document.getElementById('f1').value;
    var fname = document.getElementById('f2').value;
    if (document.getElementById('m').selected) {
        gender = document.getElementById('m').value;
    }
    else if (document.getElementById('f').selected) {
        gender = document.getElementById('f').value;
    }
    else {
        gender = document.getElementById('o').value;
    }
    var dob = document.getElementById('b1').value;
    document.write("Here is the Summary of Your Results");
    document.write("Your Name Is: ");
    document.write(name + "<br/>");
    document.write("Your Father Name Is: ");
    document.write(fname + "<br/>");
    document.write("Your Gender Is: ");
    document.write(gender + "</br>");
    document.write("Your Date of Birth Is: ");
    document.write(dob + "</br>");

utilities / converter.js

appsrc is-live=true do-timestamp=true name=audiosrc ! opusparse ! oggmux ! filesink location=test.ogg

utilities / index.js

export default class Calculator {
    // class functions here
}

app.js

export default class Converter {
    // class functions here
}

1 个答案:

答案 0 :(得分:1)

在app.js中,您可以使用import { Calculator, Converter } from './utilities';,并且您的代码应类似于

import { Calculator, Converter } from './utilities';

const calculator = new Calculator();
const converter = new Converter();