小程序(获取用户信息,分享功能)

获取用户信息

版本小于16.0.1的情况

1.在wxml文件中

<button open-type="getUserInfo" bindgetuserinfo="huode" type="primary" >授权</button>

2.在js文件中

// pages/user/user.js
Page({

  huode(res){
    console.log(res);
  },

})

3.运行结果

点击授权按钮后点击弹窗中的允许按钮.

 

 

高版本

1.wxml

<button bindtap="shouquan" >授权</button>

2,js文件中

// pages/user/user.js
Page({
  shouquan(){
    wx.getUserProfile({
      desc: 'desc',
      success(res){
        console.log(res);
      }
    })
  },
})

3.运行结果

 

微信分享功能

直接在wxml文件中输入


<button open-type="share">分享</button>

 


版权声明:本文为qq_38998319原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。