当前位置:网站首页>How to handle the small program tabbar that does not support parameter transfer
How to handle the small program tabbar that does not support parameter transfer
2022-06-26 09:04:00 【CMS applet plug-in [official]】
Whether it is Baidu applet or wechat applet ,app.json Stipulated in tabbar The page does not support parameter transfer , for example :
code Jianteng stone station
- <navigator url='../service/service?typeid=6' openType="switchTab">
- Service project
- </navigator>
above navigater Jump has an attribute :openType="switchTab" It means to open tabbar page service, Although there is a parameter typeid=6, however typeid=6 Not really tabbar Page to receive , Cause open tabbar Pages are used for default columns .
(1) First step : adopt bindtap Binding method triggers cache , hold typeid Save up
although tabbar Parameter transfer is not supported , But we can get the passed parameters by caching , So the one above navigator The direct jump is not enough , You need to encapsulate a method :
- <view class='service_li' bindtap='show_service' data-typeid='11' data-listtype='3'>
- Service project
- </view>
index Page “ Service project ” adopt bindtap Bind one show_service Method , This show_service Will be passed on to the next data-* All the parameters inside .
stay index.js Write in show_service Method :
- show_service: function (e) {
- var data = e.currentTarget.dataset;
- var title = data.title; // Get the delivered title
- var typeid = data.typeid; // Get the delivered typeid
- var listtype = data.listtype; // Get the delivered listtype
- // adopt setStorageSync Methods will typed Deposit in stypeid in , You can choose your own name
- wx.setStorageSync('stypeid', typeid)
- wx.switchTab({ // adopt switchTab Method to jump to the corresponding page
- url: '/pages/service/service?typeid=' + typeid + "&title=" + title + "&listtype=" + listtype, // The following parameters are actually invalid and can be written directly as :‘/pages/service/service’
- })
- },
In this way, we will transfer the parameters that users click on the home page typeid Stored in the cache
(2) The second step : stay service To get typeid
stay service.js Medium onload perhaps onshow Add typeid Methods , In order to be compatible with users, it is directly through tabbar The situation of entry , Need a default typeid, Reference code :
- var stypeid = wx.getStorageSync('stypeid');// Get... Through cache typeid
- var typeid = stypeid ? stypeid : that.data.typeid; // If stypeid There is a read , Otherwise, read the default typeid
Then we can go directly through getList() Method to read directly api Get the content list
- that.getList(typeid);
explain :
(1) If you don't go through the homepage show_service Methods into the service Page , Then the update cache will not be triggered , therefore typeid It's not going to change , By clicking on tabbar Get into service The page will always show a certain page , You can onHide Add a reset or condition to the method stypied Methods , However, it is not recommended to do so
(2)service After switching columns of the page , We can do it in switch_tab Method to modify the cache , Dynamically stored in the current column typeid
- switch_cat: function (e) {
- var that = this;
- var CATEGORYS = wx.getStorageSync('categorys')// Call column cache
- var data = e.currentTarget.dataset;
- var typeid = data.typeid;
- var listtype = data.listtype;
- var curtypeid = data.typeid;
- that.setData({
- curtypeid: curtypeid,
- listtype: listtype,
- page: 1
- })
- wx.setNavigationBarTitle({
- title: CATEGORYS[curtypeid]['typename'] + '-' + wx.getStorageSync('system').seotitle
- });
- that.getList(typeid);
- },
however , When switching Columns , Do you want to change the cache , According to your own needs , There is no need to switch
Empathy , If you set up a news page 、 The same method can be used for the case page and other pages Put it in the cache and then the news 、 The case judges the columns to be displayed by caching
Like news :
- wx.setStorageSync('newsid', typeid)// Deposit in newsid
边栏推荐
- 浅谈一下Type-C接口发展历程
- 【300+精选大厂面试题持续分享】大数据运维尖刀面试题专栏(一)
- phpcms小程序接口新增万能接口get_diy.php
- Pandas vs. SQL 1_ nanyangjx
- [IVI] 15.1.2 system stability optimization (lmkd Ⅱ) psi pressure stall information
- Yolov5进阶之四训练自己的数据集
- cookie session 和 token
- Practice is the fastest way to become a network engineer
- HDU - 6225 little boxes (\u int128)
- Isinstance() function usage
猜你喜欢

【300+精选大厂面试题持续分享】大数据运维尖刀面试题专栏(一)

Selenium 搭建 Cookies池 绕过验证反爬登录

Fourier transform of image

yolov5进阶之零环境快速创建及测试

phpcms v9去掉phpsso模块

Yolov5进阶之一摄像头实时采集识别

Yolov5进阶之四训练自己的数据集

Euler function: find the number of numbers less than or equal to N and coprime with n

Phpcms mobile station module implements custom pseudo static settings

Yolov5进阶之二安装labelImg
随机推荐
编程训练7-日期转换问题
phpcms v9后台增加阅读量字段,可任意修改阅读量
Trimming_ nanyangjx
【云原生 | Kubernetes篇】深入万物基础-容器(五)
[300+ continuous sharing of selected interview questions from large manufacturers] column on interview questions of big data operation and maintenance (I)
Detailed explanation of traditional image segmentation methods
Clion installation + MinGW configuration + opencv installation
Pandas vs. SQL 1_ nanyangjx
1.21 study gradient descent and normal equation
Regular Expression 正则表达式
Euler function: find the number of numbers less than or equal to N and coprime with n
修复小程序富文本组件不支持video视频封面、autoplay、controls等属性问题
Selenium 搭建 Cookies池 绕过验证反爬登录
小程序首页加载之前加载其他相关资源或配置(小程序的promise应用)
[program compilation and pretreatment]
基于SSM的电脑商城
phpcms小程序插件4.0版正式上线
Yolov5进阶之二安装labelImg
深度学习论文阅读目标检测篇(七)中文版:YOLOv4《Optimal Speed and Accuracy of Object Detection》
ImportError: ERROR: recursion is detected during loading of “cv2“ binary extensions. Check OpenCV in