[Uniapp development applet] Click to get the mobile phone number (use @getphonenumber)

1. Implementation effect
insert image description here
2. Code implementation:

<template>
	<view>
		<view class="shopadd" v-if="info.mobile">{
   
   {info.mobile}}</view>
		<button class="getNumber" v-else open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">点击获取手机号</button>
	</view>
</template>

<script>
	export default {
      
      
		data() {
      
      
			return {
      
      
				info: {
      
      }, //个人信息
			}
		},
		methods: {
      
      
			// 获取手机号
			getPhoneNumber(e) {
      
      
				console.log(e)
				var that = this;
				if (e.detail.code) {
      
      
					this.$api.appPlateForm('POST', this.$url.getPhoneNumber, {
      
      
						code: e.detail.code,
					}, function(res) {
      
      
						if (res.code == '200') {
      
      
							uni.setStorageSync('getPhone',res.data.phone)
							console.log('打印获取的手机号',uni.getStorageSync('getPhone'))
							that.info.mobile = res.data.phone
						}
					})
				}else{
      
      
					
				}
			},
		}
	}
</script>

Guess you like

Origin blog.csdn.net/weixin_48596030/article/details/131479881