当前位置:网站首页>Applet: how to get the user's mobile number in the plug-in
Applet: how to get the user's mobile number in the plug-in
2022-06-12 15:57:00 【Front end life of Lvan】
background
We know , It cannot be used in applet plug-ins open-type relevant API Of , Official documents There are also detailed instructions 
But if we want to make a login related plug-in , Is to get the user's mobile number , How do you do that , It can be used Refer to the custom component function of the applet
Introduce the custom component functions of the reference applet
Part of a plug-in ( Whether it's a component or a page ) You can pass in a component to render through an applet .
practice
Small program end
Introducing plug-ins
"plugins": {
"auth-login": {
"version": "dev",
"provider": "wxxxxxxxx",
"genericsImplementation": {
"auth-login-default": {
// Put this component (get-phone-number-btn) To the plug-in page (auth-login-default) Rendering
"get-phone-number-btn": "components/get-phone-number-btn/index"
}
}
}
},
Follow this path in the applet components/get-phone-number-btn/index , Create a new component
index.js
Component({
properties: {
show: {
type: Boolean,
value: false
},
phoneStyle: {
type: String,
value: ''
}
},
methods: {
getPhoneNumber (e) {
console.log('e', e)
this.triggerEvent('getPhoneNumber', e.detail)
}
}
})
index.wxml
<button wx:if="{
{ show }}" class="btn-com ok" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber" style="{
{
phoneStyle }}"> Wechat authorized login </button>
index.json
{
"component": true,
"usingComponents": {
}
}
Plug in side
For example, there is a page on the plug-in side , It's called auth-login-default, Can be in plugin.json View in .
plugin.json
{
"publicComponents": {
},
"pages": {
"auth-login-default": "pages/auth-login/index"
},
"main": "index.js"
}
"auth-login-default": "pages/auth-login/index" The code in this page is as follows :
index.wxml
<text> I am the original code of the plug-in </text>
// I am a component passed in by an applet
<get-phone-number-btn show="{
{ loginCode && !token && checked }}" bind:getPhoneNumber="getPhoneNumber" phoneStyle="width: 100%;height: 88rpx;line-height: 88rpx;text-align: center;border-radius: 44rpx;border: none;font-size: 32rpx;border: none;outline: none;background: #02C160;color: #fff;" />
index.json
"componentGenerics": {
"get-phone-number-btn": true
}
index.js
Page({
async getPhoneNumber (e) {
// Get your mobile number
console.log(e.detail)
}
})
effect
Final , We see this plug-in page (auth-login-default) The effect of 
After clicking, you can also adjust the pop-up window of the authorized mobile phone number ~
边栏推荐
- POSTMAN-REST Client插件的应用
- nohup 命令使用
- Codeforces Round 797 (Div. 3,CF1690)全题解
- With a lamp inserted in the nostril, the IQ has risen and become popular in Silicon Valley. 30000 yuan is enough
- Daily leetcode - 3 Longest substring without duplicate characters
- Apache kylin Adventure
- [jvm learning] local method stack and heap
- 写代码也有本手俗手之分,而我们要善于发现妙手!
- < 山东大学软件学院项目实训 > 渲染引擎系统——基础渲染器(六)
- Solution to idea Chinese prism garbled code error -- console Chinese output prism garbled code
猜你喜欢

< 山东大学软件学院项目实训 > 渲染引擎系统——辐射预计算(九)

写代码也有本手俗手之分,而我们要善于发现妙手!

Defer learning in golang

Fiddler packet capturing (mobile app)

Two ways of array simulating queue

From K-means to capsule

Solution of user and root forgetting password in virtual machine

从斐波那契数列求和想到的俗手、本手和妙手

【工具推荐】个人本地 markdown 知识图谱软件 Obsidian

2022.02.28 - SX11-05. The largest rectangle in the histogram
随机推荐
使用CSDN-markdown编辑器
Data analysis | kmeans data analysis
How to analyze the running time and CPU utilization of Go programs?
CUDA out of memory 或 BrokenPipeError: [Errno 32] Broken pipe 或 OSError: [WinError 1455] 页面文件太小的解决办法
redis 通用命令
Classic case of solidity - Smart games
Find the number of cells (connectivity map, wide search, deep search)
[jvm learning] class loading subsystem
From K-means to capsule
Difference between tinyint and int
[jvm learning] parental delegation mechanism and PC register (program counter)
TCP与UDP的区别,以及TCP的三次握手和TCP的四次挥手
同源?跨域?如何解决跨域?
MySQL blob and text types
FPGA (III) trigger and latch
Introduction and download website of common data of GIS, remote sensing, hydrology and Geography (2), supplementary~
Install RHEL 7/8 (red hat) virtual machine (Reprint)
Interface.
PHP builds a high-performance API architecture based on sw-x framework (II)
第一章 线性表