当前位置:网站首页>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
边栏推荐
- How can an organization judge the success of data governance?
- 什么是幂等性?四种接口幂等性方案详解!
- rider内Mono脚本找不到引用资源
- POJ 2891 Strange Way to Express Integers (扩展欧几里得)
- GPU accelerated Pinterest recommendation model, the number of parameters increased by 100 times, and the user activity increased by 16%
- Research on motion capture system for indoor combined positioning technology
- 8月份DB-Engines 数据库排行榜最新战况
- 力扣练习——60 二叉搜索子树的最大键值和
- 用proteus直接仿真stm32-可以完全丢弃编程器
- Pycharm终端出现PS问题、conda或activate不是内部命令问题..
猜你喜欢
振弦传感器及核心VM系列振弦采集模块
GPU accelerated Pinterest recommendation model, the number of parameters increased by 100 times, and the user activity increased by 16%
LAXCUS分布式操作系统安全管理
英特尔推送20220809 CPU微码更新 修补Intel-SA-00657安全漏洞
Cybersecurity Notes 5 - Digital Signatures
使用哈工大LTP测试分词并且增加自定义字典
第3章-线性方程组(3)
从产品角度看 L2 应用:为什么说这是一个游乐场?
[E-commerce operation] Do you really understand social media marketing (SMM)?
Kyligence 通过 SOC 2 Type II 审计,以可信赖的企业级产品服务全球客户
随机推荐
【勇敢饭饭,不怕刷题之链表】有序链表的合并
Hangdian Multi-School-Loop-(uncertainty greedy + line segment tree)
谷歌数据中心发生“电力事故”造成 3 人受伤
基于UiAutomator2+PageObject模式开展APP自动化测试实战
The brave rice rice, does not fear the brush list of 】 list has a ring
杭电多校-Loop-(不确定性贪心+线段树)
POJ 2891 Strange Way to Express Integers (Extended Euclidean)
【勇敢饭饭,不怕刷题之链表】链表倒数节点问题
力扣练习——63 找到字符串中所有字母异位词
学长告诉我,大厂MySQL都是通过SSH连接的
【无标题】
Chapter 22 Source Code File REST API Reference (4)
用proteus直接仿真stm32-可以完全丢弃编程器
Kyligence 通过 SOC 2 Type II 审计,以可信赖的企业级产品服务全球客户
Some tips for using Unsafe
三个绘图工具类详解Paint(画笔)Canvas(画布)Path(路径)
Short video software development - how to break the platform homogenization
快速上手,征服三种不同分布式架构调用方案
LeetCode_152_乘积最大子数组
OSSCore 开源解决方案介绍