小程序小程序 | 缓存import {HTTP} from '../util/http.js'; class classicModel extends HTTP{ getLatest(sCallback){ this.request({ url: 'classic/latest', success: (res) => { // console.log(res) sCallback作者王明昌发布时间2018-09-10复制import {HTTP} from '../util/http.js'; class classicModel extends HTTP{ getLatest(sCallback){ this.request({ url: 'classic/latest', success: (res) => { // console.log(res) sCallback(res)//回调返回值 this._setLatestIndex(res.index) //写入缓存 let key = this._getKey(res.index) wx.setStorageSync(key, res) } }) } //上一期下一期切换 //现在缓存中查看是否存在,如果不存在,查找服务器 getClassic(index,nextorpre,sCallback){ //确定key let key = nextorpre == 'next' ? this._getKey(index + 1) : this._getKey(index - 1) let classic = wx.getStorageSync(key) if(!classic){ this.request({ url: 'classic/' + index + '/' + nextorpre, success: (res) => { // console.log(res) //写入缓存 wx.setStorageSync(this._getKey(res.index), res) sCallback(res)//回调返回值 } }) }else{ sCallback(classic) } } // 第一期 isFirst(index){ return index == 1 ? true : false } // 最后一期 isLast(index) { let latestIndex = this._getLatestIndex() return index == latestIndex ? true : false } // 写入缓存 _setLatestIndex(index) { wx.setStorageSync('latest', index) } // 读取缓存 _getLatestIndex() { let index = wx.getStorageSync('latest') return index } //获取期刊的key _getKey(index){ let key = 'classic-'+index return key } } export{classicModel}
2018-12-09小程序 | 在首页判断是否登录并跳转到登陆界面login //index.js import { config } from '../../config.js' Page({ /** * 页面的初始数据 */ data: { //判断小程序的AP
2019-07-22小程序判断是否包含某个字符(数组和字符串)console.log(['x', 'a'].indexOf('a')); // 1 console.log('dbac'.indexOf('aa')); // -1
2018-12-09小程序 | 在首页判断是否登录并登陆执行index.wxml //其他业务 我知道了 index.js import { config } from '../../config.js' // pages/index/index.js Pag
2018-10-07小程序组件 | mask遮罩层组件定义组件 wxml: wxss .container{ background-color: #000; position: fixed; top: 0; opacity: 0.6; width: 10
2018-12-09微信小程序 form表单input变化时自动搜索index.wxml 搜索 取消 index.js inputTyping: function (e) { var title = e.detail.value; console.log(e) //
2018-12-09小程序 | 小程序中使用关注公众号功能实现在小程序中显示公众号,点击后进行关注 使用组件 使用说明 使用组件前,需前往小程序后台,在“设置”->“接口设置”->“公众号关注组件”中设置要展示的公众号。 注:设置的公众号需与小程序主体一致。