菜谱小程序开发简单记录

2022-05-301091

菜谱小程序(uniapp) 1、上线编译配置 开发这工具/本地设置 "mp-weixin" : { "appid" : "wx4dab0691dee374dc", "setting" : { "urlCheck" : true, //是否合法校验 "es6" : true, //编译成es6 "minified" : true //是否压缩 }, "usingComponents" : true, "lazyCodeLoading" : "requiredComponents" //按需引入 }, 2、 本地存储 同步存储

uni.setStorageSync('xxx') //存储 uni.getStorageSync('xxx') //读取 uni.removeStorageSync('xxx') //删除 3、 设置公共变量 在App.vue中设置的变量和函数,通过getApp()方法可得到 //App.vue文件 methods: { getToken() { return uni.getStorageSync("token"); },

//其他.vue页面 getApp().getToken() //读取getToken方法返回uni.getStorageSync("token") 4、 获取页面栈 可读取其他页面的数据(包括方法)在当前页面修改之前页面的数据可以调用他的方法进行修改 let pages = getCurrentPages(); //获取到页面栈(以数组形式排列,索引0为首页,长度减1为当前页,长度减2为当前上一页) let prePages = pages[pages - 2]
5、上拉加载加更多 onReachBottom 钩子函数,监听页面触底监听,当页面触底时触发,注: 页面没有超出设备高度不会触发或设置了overflow,或标签使用srcoll-view都不触发

data() { return { total: 0, pageNum: 0, list:[] } }, onLoad() { this.getList();
}, onReachBottom() { this.getList(); } methods: { getList() { this.pageNum ++; let params = { pagesNum: this.pageNum, pageSize: 10, }; const {rows, total} = this.$http.getList(params); if(!rows.length) { uni.showToast({ title: '没有更多了~', duration: 200, icon: 'none' }); return; } this.list.push(...rows); this.total = total; }

分享
点赞0
打赏
上一篇:代理工具Fiddler -调试与替换接口状态
下一篇:vuex的使用