let localMap = new Map(),// 定义一个全局的MAP对象 typeCode = ''; // 点击分类里面的细分选项卡 handleClickTabs(e) { let id = e.target.dataset.index, code = e.target.dataset.id; typeCode = code;// 这里定义code,在请求回调里面使用 this.setData({ leftTab : id }); if (localMap!=null) {// map对象 let list = localMap.get(typeCode);//获取对应分类的type的code if (list!=null) {//map里面有值,渲染页面 this.setData({ tabSonList:list }) }else {//map里面没有值,去请求接口 const data = { goodsTypeCode: code }; utils.sendRequest(api.ClassifySon, data, this.handleGoodsSon.bind(this)); } }else { const data = { goodsTypeCode: code }; utils.sendRequest(api.ClassifySon, data, this.handleGoodsSon.bind(this)); } }, //分类里面的内容 handleGoodsSon(res) { let list = res.data; localMap.set(typeCode,list)//存对应typeCode的list this.setData({ tabSonList:list }) },
In this way, the optimization of the tab will be reassigned if the interface data becomes too much. Although I am adding drama to myself, this is also my work attitude. I have learned new things and optimized the project.
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
Using rpx for WeChat mini program development
##How to create a page for WeChat mini program development
The above is the detailed content of How to use Map objects in WeChat applet development. For more information, please follow other related articles on the PHP Chinese website!