Explorar el Código

优化头像更改后信息传输方法

wangxin hace 6 años
padre
commit
281337f803
Se han modificado 2 ficheros con 8 adiciones y 4 borrados
  1. 7 4
      pages/person/person.js
  2. 1 0
      pages/userinfo/userinfo.js

+ 7 - 4
pages/person/person.js

@@ -44,7 +44,12 @@ Page({
   onLoad: function(options) {
     if (wx.getStorageSync('userid')) {
       // 获取用户信息
-      app.utils.getHwUserInfo(this)
+      app.utils.getHwUserInfo(this);
+      wx.$watch('userinfo', this, (data) => {
+        this.setData({
+          userinfo: data
+        })
+      })
     } else {
       wx.reLaunch({
         url: '/pages/login/login',
@@ -63,9 +68,7 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow: function() {
-    this.setData({
-      userinfo: wx.getStorageSync('userinfo')
-    })
+
   },
 
   /**

+ 1 - 0
pages/userinfo/userinfo.js

@@ -22,6 +22,7 @@ Page({
           url: wx.kx_api.hwUser.changeAvatar
         }).then((data) => {
           wx.setStorageSync('userinfo', data[0].hwUser);
+          wx.$emit('userinfo', data[0].hwUser)
           this.setData({
             userinfo: data[0].hwUser
           })