Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Methods of Module Export and Import in node and ES6

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

In this article Xiaobian for you to introduce in detail "node and ES6 module export and import method", the content is detailed, the steps are clear, the details are handled properly, I hope this "node and ES6 module export and import method" article can help you solve your doubts, the following follow the editor's ideas slowly in-depth, together to learn new knowledge bar.

Export and Import of node

Export syntax for 1.node

Var path = {} module.exports = path

Import syntax for 2.node

Const path = require ('path')

Export and Import of ES6

Export syntax for 1.ES6

Export default {} (only one member can be exposed) export var s = {} export var b = {} (multiple members can be exposed)

Import syntax for 2.ES6

Import a from 'package name (or file path)' (import export default leak members) import {s} from 'package name (or file path)' (import export leak members with the same name)

Examples add:

/ / ordinary export export {name:'zs', age: 20} / / the exported module defaults to the user's name, and can only be exported once using default. Other modules exported by export default {name:'zs', age: 20} / / export var title = "Little Star" export var content = "ha"

Import instance

Import {name,age} from'. / test.jsimport M1 from'. / test.jsimport {title,content} from'. / test.js'console.log (M1) console.log (title+ "-" + content) here, this article "methods of module export and import in node and ES6" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report