index.js 760 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import {
  2. getUserInfo,
  3. setFans
  4. } from '~/api/user'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. userInfo: {}
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad(options) {
  16. this.getUserInfo()
  17. },
  18. async getUserInfo() {
  19. let res = await getUserInfo({
  20. uid: '16c02342a44f45d78bb25b52ae6082ae'
  21. })
  22. console.log(res);
  23. this.setData({
  24. userInfo: res
  25. })
  26. },
  27. // 关注
  28. async setFans() {
  29. let newLike = !this.data.userInfo.like
  30. console.log(newLike);
  31. await setFans({
  32. uid: this.data.userInfo.user.uid
  33. }, 'put')
  34. this.setData({
  35. ['userInfo.like']: newLike
  36. })
  37. wx.showToast({
  38. title: newLike ? '已关注' : '取消关注',
  39. icon: 'none'
  40. })
  41. },
  42. })