自從小程序文檔更新后,自動授權(quán)已不存在啦
目前的授權(quán)都是通過button來實(shí)現(xiàn)的,具體知識點(diǎn)可參考小程序的官方文檔,以下是我做的一個(gè)小demo(進(jìn)入首頁,跳出一個(gè)登錄彈出框,彈出框是自己寫的一個(gè)UI組件),廢話不多說,直接上代碼
UI組件部分(modal)
modal.wxml
<view class='modal-mask' wx:if='{{show}}' bindtap='clickMask'> <view class='modal-content'> <scroll-view scroll-y class='main-content'> <slot></slot> </scroll-view> </view></view>modal.wxss
n: fixed; left: 0; right: 0; top: 0; bottom: 0; background-color: rgba(0,0,0,0.5); z-index: 999;}/*遮罩內(nèi)容*/.modal-content{ display: flex; flex-direction: column; width: 65%; background-color: #fff; border-radius: 10rpx; padding: 20rpx; text-align: center;}/*中間內(nèi)容*/.main-content{ flex: 1; height: 100%; overflow-y: hidden; max-height: 80vh; /* 內(nèi)容高度最高80vh 以免內(nèi)容太多溢出*/}.bottom { border-radius: 80rpx; margin: 70rpx 50rpx; font-size: 35rpx;}modal.js
Component({ /** * 組件的屬性列表 */ properties: { //是否顯示modal彈窗 show: { type: Boolean, value: false }, //控制底部是一個(gè)按鈕還是兩個(gè)按鈕,默認(rèn)兩個(gè) single: { type: Boolean, value: false } }, /** * 組件的初始數(shù)據(jù) */ data: { }, /** * 組件的方法列表 */ methods: { // 點(diǎn)擊modal的回調(diào)函數(shù) clickMask() { // 點(diǎn)擊modal背景關(guān)閉遮罩層,如果不需要注釋掉即可 this.setData({ show: false }) }, // 點(diǎn)擊取消按鈕的回調(diào)函數(shù) cancel() { this.setData({ show: false }) this.triggerEvent('cancel') //triggerEvent觸發(fā)事件 }, // 點(diǎn)擊確定按鈕的回調(diào)函數(shù) confirm() { this.setData({ show: false }) this.triggerEvent('confirm') } }})modal.json
{ "component": true, "usingComponents": {}}pages頁面
home.wxml(這個(gè)是彈框,home頁面內(nèi)容直接在下面加一個(gè)<view>這里寫home頁面的內(nèi)容</view>)
<!-- modal彈窗--> <modalView show="{{showModal}}" bindcancel="modalCancel" bindconfirm='modalConfirm' single='{{single}}'> <view class='modal-content'> <scroll-view scroll-y class='main-content'> <view wx:if="{{canIUse}}" > <view class='header'> <text>提示</text> </view> <view class='content'> <image src="/images/goods_img2.png"></image> <text>是否登錄并繼續(xù)使用該程序</text> </view> <view class="header_title"> <text class="dian">•</text> <text>登錄程序需進(jìn)行微信授權(quán)</text> </view> <view class="modal_footer"> <view class="bottom"> <button class='bottom_a'> 拒絕 </button> <button class='bottom_b' open-type="getUserInfo" lang="zh_CN" bindgetuserinfo="bindGetUserInfo"> 去登錄 </button> </view> </view></view> </scroll-view> </view> </modalView>
新聞熱點(diǎn)
疑難解答
圖片精選