当前位置:网站首页>WeChat applet, global variables change in one place and the state in other places also changes.
WeChat applet, global variables change in one place and the state in other places also changes.
2022-08-10 11:33:00 【summer thinking】
I have a mask layer with a button to hide it. It appears on many pages. How can I ensure that if I click hide on one of the pages, the other pages will not appear?
I have displayed the mask layer of this official account on all three tab pages, but I clicked delete on one of the pages, and the other pages were not displayed.
Write it as a public component.Listening in components, two life cycles
lifetimes: // life cycle function, which can be a function, or a method name defined in the methods section pageLifetimes: // the life cycle of the page where the component is locatedFunction
In both life cycles, the current global variable must be assigned to
app.js inside the definitionshowOfficial
globalData: {showOfficial:true,//Whether to display the bar that follows the official account},
official-bar.js
const app = getApp();Component({/*** Component property list*/properties: {},/*** The initial data of the component*/data: {show:true,checkIcon: 'https://wechat/static/wechat/check.png',deleteIcon: 'https://wechat/static/wechat/deleteIcon.png',}, lifetimes: {attached: function() {this.setData({show:app.globalData.showOfficial})},},pageLifetimes: {show: function() {this.setData({show:app.globalData.showOfficial})// page is displayed},},/*** List of methods of the component*/methods: {//focus onclickMask() {wx.navigateTo({url: "/pages_subpack/officialAccount/officialAccount"})},// hide the current maskdelBar() {app.globalData.showOfficial=false;//Change the value of the global variablethis.setData({show: false})},}})
official-bar.wxml
Follow the official account, automatic reminders in class
official-bar.wxss
.modal-mask{display: flex;justify-content: center;align-items: center;position: fixed;left: 0;right: 0;bottom: 0;background: rgba(0, 0, 0, 0.6);z-index: 99;height:76rpx;}/*mask content*/.modal-content{color:#fff;display: flex;justify-content:space-evenly;align-items: center;text-align: center;font-size:32rpx;padding-left: 20rpx;width: 100%;}/*Intermediate content*/.main-content{flex: 1;height: 100%;overflow-y: hidden;max-height: 80vh; /* The content height is up to 80vh to avoid overflowing too much content*/}.check-icon{padding-right:18rpx;width:32rpx;height:32rpx;}.delete-icon{width:38rpx;height:38rpx;}.delete-area{height: 69rpx;line-height: 86rpx;padding: 0 20rpx;}.payAttention{background-color: #EB8207 !important;border:none;border-radius: 76rpx;width: 160rpx;height:52rpx;line-height: 52rpx;font-size:28rpx;padding:0;margin: 0 0 0 20rpx;}
Introduced in json
"official-bar": "/components/official-bar"
The page you want to use
边栏推荐
- POJ 2891 Strange Way to Express Integers (Extended Euclidean)
- 接口定义与实现
- Programmers pursue technology to consolidate basic learning route suggestions
- 不止跑路,拯救误操作rm -rf /*的小伙儿
- 如何使用工程仪器设备在线监测管理系统
- 面试官:项目中 Dao、Service、Controller、Util、Model 怎么划分的?
- 实现内网穿透的最佳解决方案(无实名认证,完全免费)
- HDU 1520 Anniversary party (tree dp)
- 力扣练习——62 有效的数独
- Double.doubleToLongBits()方法使用
猜你喜欢
学长告诉我,大厂MySQL都是通过SSH连接的
1-IMU参数解析以及选择
HCIP ---- VLAN
4 of huawei offer levels, incredibly side is easing the bit in the interview ali?
快速上手,征服三种不同分布式架构调用方案
老板加薪!看我做的WPF Loading!!!
runtime-core.esm-bundler.js?d2dd:218 Uncaught TypeError: formRef.value?.validate is not a function
基于UiAutomator2+PageObject模式开展APP自动化测试实战
实现内网穿透的最佳解决方案(无实名认证,完全免费)
L2 applications from a product perspective: why is it a playground?
随机推荐
Programmers pursue technology to consolidate basic learning route suggestions
学长告诉我,大厂MySQL都是通过SSH连接的
三相380V整流后的电压
Store limited time seckill function system
【勇敢饭饭,不怕刷题之链表】链表中有环的问题
[Go WebSocket] 多房间的聊天室(一)思考篇
基于UiAutomator2+PageObject模式开展APP自动化测试实战
StoneDB 文档捉虫活动第一季
SQL优化最强总结 (建议收藏~)
OneFlow源码解析:算子指令在虚拟机中的执行
Kyligence 通过 SOC 2 Type II 审计,以可信赖的企业级产品服务全球客户
不止跑路,拯救误操作rm -rf /*的小伙儿
AUTOCAD——减少样条曲线控制点数、CAD进阶练习(三)
关于“码农”的一点自嘲解构
【小程序 | 启航篇】一文打通任督二脉
Short video software development - how to break the platform homogenization
Gold, nine, silver and ten job-hopping seasons: technical interview questions and answers on Alibaba, Baidu, JD.com, and Meituan
POJ 1026 Cipher (Permutation Groups)
ENVI 5.3软件安装包和安装教程
Article take you understand interrupt the key driver of polling mechanism