当前位置:网站首页>export , export default, import complete usage
export , export default, import complete usage
2022-07-30 07:52:00 【cplvfx】
A. Canonical file name
We are sure we have a file that is common.js
This file is in the static folder of the root directory
The path is as follows
|-root directory/static/common.js
export and import
One, export (export) separate writing method
export function getCookie(cname) {var name = cname + "=";var ca = document.cookie.split(';');for (var i = 0; i < ca.length; i++) {var c = ca[i];while (c.charAt(0) == ' ') c = c.substring(1);if (c.indexOf(name) != -1) {return c.substring(name.length, c.length);}}return "";}export function setCookie(cname, cvalue, exdays) {var d = new Date();d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));var expires = "expires=" + d.toGMTString();document.cookie = cname + "=" + cvalue + "; " + expires + ";path=/;domain=.baidu.cc";// setCookies(cname, cvalue, exdays);};var Domains = {baidu:'http://www.baidu.cc',};export {Domains};
The above code can see that "each is written", what is it like when it is introduced?
We import and print
Second, import (introduction)
2.1, "*" introduces all
//Introduce allimport * as commonjs from "/static/common";
console.log('commonjs==',commonjs)
We can see from the above picture that the [*] sign is used when importing, and everything can be imported
2.2, import by specified name
//Specify the name to importimport {Domains} from "/static/common";console.log('Domains==',Domains)
Three, export default
export function getCookie(cname) {var name = cname + "=";var ca = document.cookie.split(';');for (var i = 0; i < ca.length; i++) {var c = ca[i];while (c.charAt(0) == ' ') c = c.substring(1);if (c.indexOf(name) != -1) {return c.substring(name.length, c.length);}}return "";}export function setCookie(cname, cvalue, exdays) {var d = new Date();d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));var expires = "expires=" + d.toGMTString();document.cookie = cname + "=" + cvalue + "; " + expires + ";path=/;domain=.baidu.cc";// setCookies(cname, cvalue, exdays);};var Domains = {baidu:'http://www.baidu.cc',};export {Domains};export default{name: "default"};
Introduce
//Introduce allimport * as commonjs from "/static/common";console.log('commonjs==',commonjs)
You will find that the so-called "export default" just adds an attribute named "default" when the file is imported
Further reading
边栏推荐
- 阿里二面:列出 Api 接口优化的几个技巧
- 牛客:删除公共字符
- Selenium02
- 向量三重积的等式推导证明
- 多线程基础(概念,创建,中断)
- Network Protocol 01 - Basic Concepts
- Camera coordinate system, world coordinate system, pixel coordinate system conversion, and Fov conversion of OPENGLDEFocal Length and Opengl
- 测试开发工程师成长日记003 - 接口自动化框架搭建
- Process and Scheduled Task Management
- STL源码剖析:临时对象的代码测试和理解
猜你喜欢
Application of graph computing in network security analysis
A New Paradigm for Distributed Deep Learning Programming: Global Tensor
Data types of Redis6
prometheus-federation-tls加密
Test Development Engineer Growth Diary 018 - Record of Required Questions for Test Interview (Continuous Update)
As a test leader, examine several aspects of job candidates
使用 Grafana 的 Redis Data Source 插件监控 Redis
02-Use of Cycript
不会吧,Log4j 漏洞还没有完全修复?
Process and Scheduled Task Management
随机推荐
MySQL主从复制配置搭建,一步到位
阿里一面:多线程顺序运行有多少种方法?
Graph Computing 101: Types, Languages, and Systems of Graph Computing
bin文件夹下的roslyn文件夹
Let the "label" content in Baidu map generator expand--solution
Rodrigues:旋转矩阵的向量表达
软件测试术语 - 场景测试
Test Development Engineer Growth Diary 010 - CI/CD/CT in Jenkins (Continuous Integration Build/Continuous Delivery/Continuous Testing)
进程和计划任务管理
《心智社会》—马文·明斯基
A New Paradigm for Distributed Deep Learning Programming: Global Tensor
openstack删除计算节点
STL源码剖析:class template explicit specialization代码测试和理解
Test the basics 01
Test development engineer diary 002 - starting from 0 interface automation
SE_01
prometheus-federation-tls加密
多线程进阶(CountDownLatch,死锁,线程安全集合类)
测开基础知识01
相机坐标系,世界坐标系,像素坐标系三者转换,以及OPENGLDEFocal Length和Opengl 的 Fov转换