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

注释很详细,直接上代码

新增内容:
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(){
   
    //修改全局变量为true
    const 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: {
    
  }
}
})


  

效果演示:

在这里插入图片描述

相关推荐

  1. 程序开发从入门到实战》学习

    2024-02-14 07:38:01       39 阅读
  2. 程序开发从入门到实战》学习

    2024-02-14 07:38:01       30 阅读
  3. 程序开发从入门到实战》学习

    2024-02-14 07:38:01       41 阅读
  4. 程序开发从入门到实战》学习

    2024-02-14 07:38:01       33 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-02-14 07:38:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-14 07:38:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-14 07:38:01       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-14 07:38:01       20 阅读

热门阅读

  1. Sentinel微服务保护

    2024-02-14 07:38:01       34 阅读
  2. Vue 新版 脚手架 初始化 笔记

    2024-02-14 07:38:01       28 阅读
  3. C#面:在.NET中 类 System.Web.UI.Page 可以被继承吗?

    2024-02-14 07:38:01       36 阅读
  4. docker 的常用命令详解

    2024-02-14 07:38:01       28 阅读
  5. re:从0开始的CSS之旅 14. 显示模式的切换

    2024-02-14 07:38:01       30 阅读