当前位置:网站首页>Modular import and export collation in JS
Modular import and export collation in JS
2022-06-22 07:42:00 【Huangbao ~】
- module.exports And exports yes CommonJS The specification of
- export And export default yes es6 standard
- require yes AMD Standard introduction method
- import yes es6 A grammar standard of
Applets can also be used import xx ,../ On behalf of the previous Directory ,./ Represents the current directory ,
newly build commonUtils.js file
export const getTest=()=>{
return ' Hello world ~'
}
export const getTest2= function(){
return ' Hello world '
}
export const B =' I am exporting export';
function A(){
return 'Addd';
}
function AA(){
return 'AA';
}
export const a ='1';
let dd= function(){
return 'aaaa';
}
//es6 The default is derived
export default {dd:dd,AA:AA};
// Unified export
export{
A
,AA
}
export class User{
constructor(){
this.username = '';
this.age = '';
}
print(){
console.log(" Start ");
console.log(" I'm a class user How to open it "+this.username);
console.log(" end ");
}
}
// Use module.exports after above export All the failure
// module.exports={
// A:A
// ,A:AA
// }establish index.js introduce
Import commonUtils All exports in
const commonUtils = require('../../utils/commonUtils.js');
Just introduce... As needed getTest You can use it directly ,getTest()
import { getTest } from '../../utils/commonUtils.js'
introduce export defaut The object of ,getTest Represents the introduced object
import getTest from '../../utils/commonUtils.js'
Just introduce... As needed User You can use it directly ,User
import { User } from '../../utils/commonUtils.js'
Page({
data: {
},
onLoad() {
console.log("commonUtils")
console.log(getTest);
// let d =commonUtils.aaaa;
// console.log(d());
let user = new User();
user.username =' boss Huang ';
user.print();
let user2 = new User();
user2.username =' Guibiwei ';
user2.print();
console.log("aaaaaaa1",user == user);
console.log("aaaaaaa2",user == user2);
// this.setData({
// hello:commonUtils.getTest()
// })
}
})
边栏推荐
猜你喜欢

Xmind 2022思维导图激活版资源?

Does it matter if you delete the pictures in the picture space after uploading to the store

lr 2022超详细安装教程「最新」

How to batch copy babies by sales volume in Taoying

代码覆盖率测试对编程小白的意义及其使用方法

New year's Day mall material Icon

Open version - order delivery

Microsoft Remote Desktop 10.7.6正式版

ES6 set data type de duplication of array, intersection, union and difference

Backup the method of uploading babies in Taobao stores to multiple stores
随机推荐
enable_ irq_ Wake interrupt wakes up the kernel in low power mode
Backup the method of uploading babies in Taobao stores to multiple stores
Target detection series -- detailed explanation of RCNN principle
Idea cannot connect to sqlsms
Shutter margin negative margin
Use multithreading to speed up your crawler
Detailed explanation of capturing the whole store treasure and uploading it to multiple stores
Scrollrect rewrite recycle
Chromedriver所有版本下載
Lookup encapsulation of unity monobehavior component
Flutter uses the for loop
Fmdb usage details mark
Applet vant UI implementation calls interface data and displays it
Solution to the problem of "brand abuse such as brand inconsistency and stacking in the published product information" prompted by copying and uploading
Wechat games (I)
Win openfeign from simple to deep
How to authorize a picture in a store to another store? What are the methods of unauthorized replication
FFMPEG坑
vue连接mysql数据库失败
itertools 排列组合