[Vue]js module imports and exports export default

Source: Internet
Author: User

Reference
Reference

- export default s11.仅能出现1次default2.导入时候可以随便命名3,导出时候不必写{}- 常规的导出导入1,必须{}格式2,导入时必须{}匹配3,a.js 和b.js导入main.js变量名不能重复    如果重复需 import * as obj1 from "./a.js" 的方式导
-- 栗子:导出2个变量模块的导入导出:1,导出 export2,导入 import- a.jsexport let s1 = "maotai";export let s2 = "maomao";- main.jsimport {s1, s2} from "./a.js"console.log(s1, s2);- index.html<script src="main.js" type="module"></script>
1,导入导出2,变量名重复import * as obj1 from "./a.js"console.log(obj1.a, obj1.b);import * as obj2 from "./b.js"console.log(obj2.b);
- 导出a.js的s1变量, 导入到main.js里面1.注意导出时候是{}格式2,导出时export {s1}, 导入时也必须对应 import {s1} - a.jslet s1 = "maotai";export {s1};- main.jsimport {s1} from "./a.js"console.log(s1);- index.html<script src="main.js" type="module"></script>
1.导出变量时候简写2.import有变量预解释的效果(定义)- a.jsexport let s1 = "maotai"; //可以用语句来导出- main.jsimport {s1} from "./a.js"console.log(s1);- index.html<script src="main.js" type="module"></script>
- a.jslet s1 = "maotai"; //可以用语句来导出export default s1;- main.js(可重复导入)import any from "./a.js"console.log(any);import any2 from "./a.js"console.log(any2);- index.html<script src="main.js" type="module"></script>
- 理解default的规则- a.jslet s1 = "maotai";let s2 = "maomao";//1.只能有1个default//export default s1;export default s2;//2.可以和正常的导出并存export {s1,s2}- main.js(可重复导入)import any from "./a.js"console.log(any);import any2 from "./a.js"console.log(any2);import {s1, s2} from "./a.js"console.log(s1, s2);- index.html<script src="main.js" type="module"></script>

[Vue]js module imports and exports export default

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.