当前位置:网站首页>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
边栏推荐
- isinstance()函数用法
- 1.Intro_ Math (white board derivation and reprint of station B)
- Clion installation + MinGW configuration + opencv installation
- Phpcms V9 remove the phpsso module
- In depth study paper reading target detection (VII) Chinese version: yolov4 optimal speed and accuracy of object detection
- Use of PCL
- phpcms小程序插件api接口升级到4.3(新增批量获取接口、搜索接口等)
- Tensorboard
- ROS learning notes (5) -- Exploration of customized messages
- 【程序的编译和预处理】
猜你喜欢

Isinstance() function usage

MySQL在服务里找不到(未卸载)

什么是乐观锁,什么是悲观锁

External sorting and heap size knowledge

框架跳转导致定位失败的解决方法

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

phpcms小程序插件教程网站正式上线

In depth study paper reading target detection (VII) Chinese version: yolov4 optimal speed and accuracy of object detection

Detailed explanation of traditional image segmentation methods

phpcms手机站模块实现自定义伪静态设置
随机推荐
20220623 Adobe Illustrator入门
Which software is safer to open an account on
Yolov5 advanced 5 GPU environment setup
[IVI] 15.1.2 system stability optimization (lmkd Ⅱ) psi pressure stall information
phpcms v9后台文章列表增加一键推送到百度功能
ImportError: ERROR: recursion is detected during loading of “cv2“ binary extensions. Check OpenCV in
Live review | smardaten lihongfei interprets the Research Report on China's low / no code industry: the wind direction has changed
自动化测试中,三种常用的等待方式,强制式(sleep) 、 隐式 ( implicitly_wait ) 、显式(expected_conditions)
External sorting and heap size knowledge
The solution of positioning failure caused by framework jump
关于小程序tabbar不支持传参的处理办法
【IVI】15.1.2 系统稳定性优化篇(LMKD Ⅱ)PSI 压力失速信息
ThreadLocal
Construction and verification of mongodb sharding environment (redis final assignment)
Srv6---is-is extension
[300+ continuous sharing of selected interview questions from large manufacturers] column on interview questions of big data operation and maintenance (I)
【微积分】拉格朗日乘子法
Yolov5 advanced level 2 installation of labelimg
1.17 daily improvement of winter vacation learning (frequency school and Bayesian school) and maximum likelihood estimation
Uniapp uses uparse to parse the content of the background rich text editor and modify the uparse style