uniapp获取手机号(前端部分,仅供参考~)

  1. html部分

    <template>
    	<view>
    		<view>手机号:{{phone || '请获取手机号'}}view>
    		<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">获取用户手机号button> 
    	view>
    template>
    
  2. js部分

    <script>
    	import { getPhone } from './api';
    	export default {
    		data() {
    			return {
    				phone: null
    			}
    		},
    		methods: {
    			getPhoneNumber(e) {
    				getPhone(e.detail.code).then(res => {
    					this.phone = res.phoneNum;
    				});
    			}
    		}
    	}
    </script>
    
  3. api部分

    export function getPhone(code) {
    	return request({
    		method: 'get',
    		url: `api/wxapi/getPhoneNum?code=${code}`
    	});
    }
    

你可能感兴趣的:(uniapp,前端,uni-app,javascript)