使用uni app開發微信小程式之登入模組

2022-05-01 19:00:13 字數 1268 閱讀 7843

1.當使用者未授權過,呼叫該介面將直接報錯

2.當使用者授權過,可以使用該介面獲取使用者資訊

但在實際開發中我們可能需要彈出授權詢問框,因此需要我們自己來寫模擬授權彈框(主要是對 open-type="getuserinfo">的包裹+使用者是否是第一次授權判斷來顯示該頁面

),**如下:

1.頁面結構

<

template

>

<

view

>

<

view

v-if

="iscanuse"

>

<

view

>

<

view

class

='header'

>

<

image

src='../../static/img/wx_login.png'

>

image

>

view

>

<

view

class

='content'

>

<

view

>申請獲取以下許可權

view

>

<

text

>獲得你的公開資訊(暱稱,頭像、地區等)

text

>

view

>

<

button

class

='bottom'

type

='primary'

open-type

="getuserinfo"

withcredentials

="true"

lang

="zh_cn"

@getuserinfo

="wxgetuserinfo"

>

授權登入

button

>

view

>

view

>

view

>

template

>

2.樣式

3.指令碼部分

4.最終效果如下:

wx_login.png圖:

uni app微信小程式登入授權

首先是需要用到乙個授權按鈕來觸發獲取使用者資訊授權 關鍵在於 open type 為 getuserinfo 然後有個 getuserinfo的事件,把獲取授權介面寫到該事件裡面去 方法如下 ifdef mp weixin uni.getprovider fail fail else endif 在...

使用uniapp寫微信小程式 獲取定位

獲取定位並存入快取 第一步 獲取定位 uni.getlocation uni.setstorage that.store.state.vipinfo.longitude that.longitude that.store.state.vipinfo.latitude that.latitude 在需...

微信開發之微信小程式template使用

當您的專案需要多次使用同乙個布局和樣式的時候,您就可以考慮使用template 模板 來減少冗餘 使用方式 1.新建乙個template資料夾來存放您的通用模板 2.在資料夾裡面新建乙個wxml,wxss,進行模板和樣式的定義 3.設定模板的name,以及裡面您需要定義的wxml內容 4.設定wxs...