「小程序JAVA实战」 小程序抽离公用方法进行模块化(12)
转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-12/
小程序的模块化,把砖磊成一个墩子,用的时候把整个墩子移走。js更好的调用,应用更加公用化。源码:https://github.com/limingios/wxProgram.git 中的No.7
小程序的模块化
- 抽离通用方法作为通用函数
构建utils-common类
- 官方的阐述
>https://developers.weixin.qq.com/miniprogram/dev/framework/app-service/module.html

- 程序演示
events.js
//events.js
//获取应用实例
const app = getApp()
var common = require('../untils/common.js')
Page({
data: {
motto: 'Hello World',
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo')
},
clickMe: function(e){
console.log("你点击我这里出来了!")
console.log(e)
console.log(e.currentTarget.dataset.fordate)
common.sayHello("公众号:编程坑太多")
common.sayGoodbye("[编程坑太多]")
}
})
common.js
// common.js
function sayHello(name) {
console.log(`Hello ${name} !`)
console.log("Hello "+name+" !")
}
function sayGoodbye(name) {
console.log(`Goodbye ${name} !`)
console.log("Goodbye " + name + " !")
}
module.exports.sayHello = sayHello
exports.sayGoodbye = sayGoodbye

PS:需要注意的是
console.log(`Goodbye ${name} !`)
console.log("Goodbye " + name + " !")
区别如果用了 ${} 最外层需要用“符号,如果你喜欢老套路可以按照我的 “Goodbye ” + name + ” !” 这种。
「小程序JAVA实战」 小程序抽离公用方法进行模块化(12)的更多相关文章
- 「小程序JAVA实战」小程序的flex布局(22)
转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-22/ 之前已经把小程序的框架说完了,接下来说说小程序的组件,在说组件之前,先说说布局吧.源码:ht ...
- 「小程序JAVA实战」小程序的留言和评价功能(70)
转自:https://idig8.com/2018/10/28/xiaochengxujavashizhanxiaochengxudeliuyanhepingjiagongneng69/ 目前小程序这 ...
- 「小程序JAVA实战」小程序的举报功能开发(68)
转自:https://idig8.com/2018/09/25/xiaochengxujavashizhanxiaochengxudeweixinapicaidancaozuo66-2/ 通过点击举报 ...
- 「小程序JAVA实战」小程序的个人信息作品,收藏,关注(66)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudegerenxinxizuopinshoucangguanzhu65 ...
- 「小程序JAVA实战」小程序的关注功能(65)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeguanzhugongneng64/ 在个人页面,根据发布者个人和 ...
- 「小程序JAVA实战」小程序的视频点赞功能开发(62)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeshipindianzangongnengkaifa61/ 视频点 ...
- 「小程序JAVA实战」小程序的springboot后台拦截器(61)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudespringboothoutailanjieqi60/ 之前咱们把 ...
- 「小程序JAVA实战」小程序首页视频(49)
转自:https://idig8.com/2018/09/21/xiaochengxujavashizhanxiaochengxushouyeshipin48/ 视频显示的内容是视频的截图,用户的头像 ...
- 「小程序JAVA实战」小程序视频封面处理(48)
转自:https://idig8.com/2018/09/16/xiaochengxujavashizhanxiaochengxushipinfengmianchuli47/ 截图这块,在微信小程序工 ...
随机推荐
- SSM三大框架整合(Spring+SpringMVC+MyBatis)
一. 导包 18个必须的包 二.配置Spring MVC的web文件 <?xml version="1.0" encoding="UTF-8"?> ...
- react-redux: counter
store: import {createStore,applyMiddleware, compose} from "redux"; import thunk from " ...
- 【python】命令行解析工具getopt用法
处理命令行参数的模块 用法: opts, args = getopt.getopt( sys.args[1:], shortStr, longList) 输入: shortStr 形式如下: &q ...
- flash播放器插件与flash播放器的区别
flash插件是一个网页ActiveX控件,而flash播放器是一个exe的可执行程序.前者用于播放网页中的falsh动画,而后者用于播放本地swf格式文件.
- 部署tinyproxy透明代理服务
线上需要一个https的透明代理,开始打算用nginx,调试了一段时间发现配置较复杂且没有成功.后来用的tinyproxy做的透明代理.安装配置过程就是下载.解压.编译.安装.配置.启动一波流: 安装 ...
- centOS 7 tomcat nginx 验证码乱码
将服务部署在centOS 7上,配置完tomcat和nginx之后,启动服务后,发现验证码这样了~~~ 一开始是以为nginx的原因,但是在Ubuntu系统相同操作发现没有问题,后发现,系统的字体库中 ...
- jQuery学习_具备吸附功能的拖曳框
在线演示:http://sandbox.runjs.cn/show/2drrwkrx 关键点:保持一个不变,鼠标拖动时与边框的距离 === 鼠标左击时与边框的距离 源码: <!DOCTYPE h ...
- self = [super init] 最终解释
答: init 中调用super的 init方法来初始化自己所包含有的父类信息 1.内存分配 内存应该在[Class alloc]的时候就已经分配了,大小和类型应该由对应的Clas ...
- 二分答案(Widespread )
二分答案其实是变相贪心,这周算是被这个虐了,怎么都想不到,比如这题,一直纠结在最大值的贪心上后面队友一指点,原来可以先减去x*b,然后a-b随机分配就好了, 仔细一想没错呀,每次攻击必然受到x*b次伤 ...
- #503. 「LibreOJ β Round」ZQC 的课堂 容斥原理+Treap
题目: 题解: 比较容易发现 : \(x,y\) 的贡献是独立的. 所以可以分开考虑. 假设我们考虑 \(x\).向量在 \(x\) 方向的投影依次是 : \(\{a_1,a_2, ... ,a_n\ ...