巨大的石头

在这里寻找精彩人生

导航

javascript export default

概述

export default每个js文件或组件,只能有一个;import的时候,不加花括号。其余的,可以多个export,import的时候需要加花括号。

示例

test.js

var info={
    name:'zs',
    age:20
}
export var name1='张三'
export function f1(){
    return '王五'
}
var name2='李四'
function f2()
{
    return '钱六'
}
export {name2,f2}
export default info;

index.js

import * as utils from './utils.js';
import aaa from './test.js'
import { name1,name2,f1,f2 } from './test.js';
document.getElementById("title").innerText="执行结果:"+utils.add(10,20);
console.log(aaa);
console.log(name1);

index.html

<html>
    <head>
        <script type="module" src="./index.js"></script>
    </head>
    <body>
        <h1 id="title"></h1>
    </body>
</html>

运行结果

posted on 2024-02-14 21:23  巨大的石头  阅读(73)  评论(0编辑  收藏  举报

打赏