当前位置: 首页 > news >正文

微信小程序(四十四)鉴权组件插槽-登入检测

注释很详细,直接上代码

新增内容:
1.鉴权组件插槽的用法
2.登入检测示范

源码:

app.json

{"usingComponents": {"auth":"/components/auth/auth"}
}

app.js

App({globalData:{//定义全局变量isLoad:false}
})

index.wxml

<button type="default" bind:tap="inLoad">登入</button><button type="primary" bind:tap="outLoad">退出登入</button><auth isLoad="{{isLoad}}"><!-- 传输数据 --><view class="tip">登入以后可以查看的内容</view>
</auth>

index.wxss

.tip{font-size: 60rpx;color:palegreen; margin-top: 200rpx;padding: 0rpx 30rpx;background-color: bisque;
}

index.js

Page({data:{isLoad:false},//登入inLoad(){//修改全局变量为trueconst app=getApp()app.globalData.isLoad=true//console.log(app.globalData.isLoad)this.setData({//修改页面数据isLoad:app.globalData.isLoad})},//退出登入outLoad(){const app=getApp()app.globalData.isLoad=false//console.log(app.globalData.isLoad)this.setData({isLoad:app.globalData.isLoad})}
})

温馨提醒,以下组件不是页面,请勿建错
auth.wxml

<slot wx:if="{{isLoad}}"></slot>

auth.js

Component({behaviors: [],properties: {isLoad: {//接收数据type: Boolean,value: false}},lifetimes: {created() {},attached() {},moved() {},detached() {},methods: {}
}
})

效果演示:

在这里插入图片描述

http://www.lryc.cn/news/299351.html

相关文章:

  • 【ES】--ES集成热更新自定义词库(字典)
  • 能源管理师——为能源可持续发展护航
  • 设计模式理解:单例模式+工厂模式+建设者模式+原型模式
  • DataX源码分析 writer
  • 为自己的项目媒体资源添加固定高度
  • 家政小程序系统源码开发:引领智能生活新篇章
  • 多表查询
  • PHP开发日志 ━━ 深入理解三元操作与一般条件语句的不同
  • 多维时序 | Matlab实现RF-Adaboost随机森林结合Adaboost多变量时间序列预测
  • vue3-内置组件-Suspense
  • Rust入门:如何在windows + vscode中关闭程序codelldb.exe
  • git错误整理
  • 跟着cherno手搓游戏引擎【22】CameraController、Resize
  • 微信小程序(四十二)wechat-http拦截器
  • tomcat部署zrlog
  • Ubuntu Desktop 开机数字小键盘
  • 树莓派编程基础与硬件控制
  • autojs通过正则表达式获取带有数字的text内容
  • Android java基础_类的继承
  • nginx stream proxy 模块的ssl连接源码分析
  • C#面:Static Nested Class 和 Inner Class 有什么不同
  • LeetCode、208. 实现 Trie (前缀树)【中等,自定义数据结构】
  • java数据结构与算法刷题-----LeetCode151. 反转字符串中的单词
  • 《Java 简易速速上手小册》第8章:Java 性能优化(2024 最新版)
  • mysql全国省市县三级联动创表sql(一)
  • go面试题--使用两个goroutine交替打印数字与字母
  • DolphinScheduler-3.2.0 集群搭建
  • 07:Kubectl 命令详解|K8S资源对象管理|K8S集群管理(重难点)
  • 【设计模式】springboot3项目整合模板方法深入理解设计模式之模板方法(Template Method)
  • Windows搭建docker+k8s