
小程序封装
cc超人不会飞
这个作者很懒,什么都没留下…
展开
-
小程序:自定义控件,父控件与子控件的交互triggerEvent
实现目标,自定义控件一通用型喜欢按钮组件,包含喜欢和取消喜欢两种状态:如图 1、组件内的交互 点击爱心,UI上会变红心与空心 数据+1 -1 2、与父控件的交互,点击喜欢和取消喜欢,父控件发送网络请求 核心代码如下: 子控件 //自定义激活事件 let behavior = this.properties.like?'like':'cancel'; this.triggerEvent('like',{ behavior:behavior ...原创 2020-05-11 12:33:48 · 529 阅读 · 0 评论 -
小程序:wx.setStorageSync缓存的封装,实现缓存过期时间设置
class MyStorageManage { /** * 从缓存中获取数据 * @param key */ getStorage(key) { //从缓存中读取 let data = {} if (key && this._isReadOrSetStorage(key)) { data = wx.getStorageSync(key) } return data } /** * 获取缓存.原创 2020-05-11 10:19:07 · 3100 阅读 · 0 评论 -
小程序: 通过Promise封装wx.request
总共包含三个部分文件:1、封装的http请求文件 2、module业务文件 3、实现回调文件 1、通过Promise封装wx.request的http.js文件 import { config } from "../config.js"; import{ MyStorageManage } from "../util/MyStorageManage.js" const mSM = new MyStorageManage(); //错误码 const tips = { ...原创 2020-05-11 10:14:02 · 345 阅读 · 0 评论