ES6 模块化(Module)export和import详解 export default
ES6 模块化(Module)export和import详解 - CSDN博客 https://blog.csdn.net/pcaxb/article/details/53670097
微信小程序笔记<六>模块化 —— module.exports - MirageFireFox - 博客园 https://www.cnblogs.com/MirageFox/p/7905724.html
const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : '0' + n
}
var chkStrLength = (str, minLen) => {
if (str.length < minLen) {
return true
}
return false
}
module.exports = {
formatTime: formatTime,
chkStrLength: chkStrLength
}
var util = require('../../utils/util.js');
var chkStrLength = util.chkStrLength;
Page({
onLoad: function(option) {
console.log("加载用户中心页面,判断是否需要登录")
//校验逻辑:参数是否合法、网络环境是否异常(是否非历史地市)
console.log(wx.getStorageSync("username"))
console.log(chkStrLength(wx.getStorageSync("username"), 1))
console.log(123)
模块化 · 小程序 https://developers.weixin.qq.com/miniprogram/dev/framework/app-service/module.html
模块化
可以将一些公共的代码抽离成为一个单独的 js 文件,作为一个模块。模块只有通过 module.exports 或者 exports 才能对外暴露接口。
需要注意的是:
exports是module.exports的一个引用,因此在模块里边随意更改exports的指向会造成未知的错误。所以更推荐开发者采用module.exports来暴露模块接口,除非你已经清晰知道这两者的关系。- 小程序目前不支持直接引入
node_modules, 开发者需要使用到node_modules时候建议拷贝出相关的代码到小程序的目录中。
import wepy from 'wepy'
const notShorterStr = (str, minLen) => {
if (str.length < minLen) {
return false
}
return true
}
const isLogined = () => {
const username = wx.getStorageSync('username')
const uid = wx.getStorageSync('uid')
const gid = wx.getStorageSync('gid')
if (notShorterStr(username, 4) && notShorterStr(uid, 1) && notShorterStr(gid, 1)) {
return true
}
return false
}
export default {
notShorterStr,
isLogined
}
ES6 模块化(Module)export和import详解 export default的更多相关文章
- JS ES6中export和import详解
1.Export 模块是独立的文件,该文件内部的所有的变量外部都无法获取.如果希望获取某个变量,必须通过export输出, // profile.js export var firstName = ' ...
- ES6模块之export和import详解
ES6中的模块即使一个包含JS代码的文件,在这个模块中所有的变量都是对其他模块不可见的,除非我们导出它.ES6的模块系统大致分为导出(export)和导入(import)两个模块. 1.模块导出(ex ...
- [js高手之路] es6系列教程 - 对象功能扩展详解
第一:字面量对象的方法,支持缩写形式 //es6之前,这么写 var User = { name : 'ghostwu', showName : function(){ return this.nam ...
- require 和 import 详解
前言 JS模块化编程是前端小伙伴们必不可少的知识,下面妹子将于自认为比较清晰的方式列举出来. 1 require 特点: 1.运行时加载 2.拷贝到本页面 3.全部引入 1.1 CommonJS No ...
- css模块化及CSS Modules使用详解
什么是css模块化? 为了理解css模块化思想,我们首先了解下,什么是模块化,在百度百科上的解释是,在系统的结构中,模块是可组合.分解和更换的单元.模块化是一种处理复杂系统分解成为更好的可管理模块的方 ...
- [ES6系列-03]ES6中关于参数相关特性详解(参数默认值与参数解构赋值与剩余参数)
[原创] 码路工人 大家好,这里是码路工人有力量,我是码路工人,你们是力量. 今天总结一下 ES6 中跟参数相关的内容. 欢迎补充斧正.留言交流. 让我们互相学习一起进步. 1. ES6 参数默认值( ...
- Go依赖模块版本之Module避坑使用详解
前提 对于Go的版本管理主要用过 glide,下面介绍 Go 1.11 之后官方支持的版本管理工具 mod. 关于 mod 官方给出了三个命令 go help mod.go help modules. ...
- Python Import 详解
http://blog.csdn.net/appleheshuang/article/details/7602499 一 module通常模块为一个文件,直接使用import来导入就好了.可以作为mo ...
- python import详解
1.import作用 引入模块 2.import的特点 一个程序中,import的模块不会重复被引用,如: # test1.py import test2 print test2.attr # tes ...
随机推荐
- 前端基础之CSS_1
摘要 CSS(层叠样式表)的三种设置方法 基本选择器 组合选择器 属性选择器 分组与嵌套 伪类选择器 伪元素选择器 选择器的优先级 一些样式的设置(字体.文本.背景.边框) display属性设置 0 ...
- 计蒜客 Overlapping Rectangles (离散化)
题意: 给定一个坐标系, 给出n个矩形的左下角坐标(bx,by)和右上角坐标(tx,ty) , 求矩形覆盖的面积, 有些区域会被多个矩形覆盖, 但只用算一次. n <= 1000, 0 < ...
- netcore使用AutoMapper
说明:以下是使用过程中看到的其他博主写的,地址如下: 地址一:https://cloud.tencent.com/developer/article/1395155 地址二:https://www.c ...
- xtu read problem training A - Dividing
A - Dividing Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Descri ...
- poj3468区间延迟更新模板题
#include<stdio.h> #include<string.h> #define N 100000 struct st{ int x,y; __int64 yanc ...
- MyEclipse 6.5安装maven插件
一.卸载原有maven插件 MyEclipse 6.5集成了Maven插件,不过有不少bug,用习惯了m2eclipse,不想在这上面浪费时间.要安装m2eclipse,需要先把自带的maven插件卸 ...
- Contest Hunter #46 T1 磁力块 [花式暴力]
将所有石头按距离远近排序,将所有取到的时候扔进堆里维护最大磁力强度. 贪心,每次用强度最强的磁石尝试吸引地上的石头,扫完区间以后,这块石头就再也不会用到了. 在此基础上可以做些小优化,比如说优化未取石 ...
- 【HDOJ6324】Grab The Tree(博弈)
题意: 思路: #include <stdio.h> #include <vector> #include <algorithm> #include <str ...
- 【BZOJ1061】志愿者招募(单纯形,对偶性)
题意: 这个项目需要N 天才能完成,其中第i 天至少需要 Ai 个人. 布布通过了解得知,一共有M 类志愿者可以招募.其中第i 类可以从第Si 天工作到第Ti 天,招募费用 是每人Ci 元.新官上任三 ...
- MySQL介绍及安装&MySQL软件基本管理
mysql介绍 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司.MySQL 最流行的关系型数据库管理系统,在 WEB 应用方面MySQL是最好 ...