「小程序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/ 截图这块,在微信小程序工 ...
随机推荐
- 005——VUE中的v-text与v-html的使用
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- python基础之模块二
六 logging模块 6.1 函数式简单配置 import logging #导入模块 logging.debug('debug message') #调试消息 logging.debug('inf ...
- 条款25:考虑写出一个不抛出异常的swap函数
首先说下标准库的swap算法: namespace std{ template<typename T> void swap(T & a, T & b) { T tmp = ...
- TCP与UDP(实时通讯)
1.TCP使用 导入AsyncSocket资源文件夹,此文件是arc混编,加入库文件,如下图: #import "ViewController.h" #import "A ...
- //可以不保存在session中, 并且前面我保存在request,这里session也可以获取 chain.doFilter(request, response); //只有登录名不为空时放行,防止直接登录 成功的页面
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOE ...
- 【tensorflow:Google】四、深层神经网络
一.深度学习与深层神经网络 1.线性模型局限性 线性模型无论多少层,表达能力是一致的.可以通过激活函数实现非线性. 2.多层网络可以解决异或运算 二.损失函数定义 1.经典损失函数: 分类问题: 二分 ...
- Dojo仪表盘
Dojo提供了非常好的仪表盘显示,效果如下: <!DOCTYPE html> <html> <head> <title>Dojo仪表盘</titl ...
- Leetcode 1014. Best Sightseeing Pair
本题是leetcode121这道题的翻版,做法完全一样,也是扫一遍数组,维护两个值,一个是a[i]+i的最大值,另一个是a[i]+a[j]+i-j的最大值. class Solution: def m ...
- linux之epoll
1. epoll简介 epoll 是Linux内核中的一种可扩展IO事件处理机制,最早在 Linux 2.5.44内核中引入,可被用于代替POSIX select 和 poll 系统调用,并且在具有大 ...
- 【转载】对一致性Hash算法,Java代码实现的深入研究
原文地址:http://www.cnblogs.com/xrq730/p/5186728.html 一致性Hash算法 关于一致性Hash算法,在我之前的博文中已经有多次提到了,MemCache超详细 ...