小程序回顾

输入框

输入框:(无任何样式)有一个confirm-type的值可以设置右下角按钮的值,有一个placeholder-class的值(设置placeholder的样式)

获取用户信息
1.必须通过button来获取,不能直接调用

js.代码如下

  getUserInfo: function (e) {
    
    
    console.log(e)
    if (e.detail.errMsg === 'getUserInfo:fail auth deny') {
    
    
      wx.showToast({
    
    
        title: '您拒绝了授权,部分功能无法访问,请重新授权',
        icon: 'none'
      })
    } else {
    
    
      app.globalData.userInfo = e.detail.userInfo
      this.setData({
    
    
        userInfo: e.detail.userInfo,
        hasUserInfo: true
      })
    }

  }

html代码如下

 <button open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
2.通过open-data组件来获取(只能在html中用)

html代码如下

<open-data type="groupName" open-gid="xxxxxx"></open-data>
<open-data type="userAvatarUrl"></open-data>
<open-data type="userGender" lang="zh_CN"></open-data>
hover-class为手指点击时效果
获取用户open Id

定义一个事件,然后调用wx.login这个方法获取code,然后吧code传给接口获取open Id,然后储存(本地)
在这里插入图片描述

在小程序中挂载(通过this.$访问所有的工具函数,在js中可以无限扩展)

导出:在utils.js中吧所需要的全部引入,然后导出一个方法,最后需要return,内容如下所示
在这里插入图片描述

导入:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_49866029/article/details/108999862