editUser.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <view class="container">
  3. <view class="title">用户昵称</view>
  4. <view class="input">
  5. <uni-easyinput
  6. :errorMessage="error"
  7. v-model="userInfo.nickname"
  8. focus
  9. placeholder="请输入用户昵称"
  10. ></uni-easyinput>
  11. </view>
  12. <view class="tip">请设置2~24个字符,不包括特殊字符哦</view>
  13. <view class="button" @click="save">保存</view>
  14. </view>
  15. </template>
  16. <script>
  17. import { userInfoApi, profileApi } from '@/api/user.js'
  18. export default {
  19. data() {
  20. return {
  21. error: false,
  22. name: '',
  23. userInfo: {},
  24. }
  25. },
  26. onShow() {
  27. this.getUserInfo()
  28. },
  29. methods: {
  30. getUserInfo() {
  31. userInfoApi().then(res => {
  32. this.userInfo = res.data
  33. this.name = res.data.nickname
  34. console.log(this.userInfo, '用户信息')
  35. })
  36. },
  37. save() {
  38. if (!this.userInfo.nickname) {
  39. wx.showToast({
  40. title: '请输入用户名称',
  41. icon: 'error',
  42. })
  43. return
  44. }
  45. let params = {
  46. nickName: this.userInfo.nickname,
  47. }
  48. profileApi(params).then(res => {
  49. console.log(res, 'res')
  50. wx.showToast({
  51. title: '修改成功',
  52. })
  53. wx.navigateBack({
  54. delta: 1,
  55. })
  56. })
  57. },
  58. },
  59. }
  60. </script>
  61. <style scoped lang="scss">
  62. .container {
  63. background: #f8f8f8;
  64. padding: 30rpx 20rpx;
  65. .title {
  66. margin-bottom: 30rpx;
  67. color: #333333;
  68. font-size: 28rpx;
  69. padding: 0 20rpx;
  70. }
  71. .input {
  72. margin-bottom: 30rpx;
  73. }
  74. .tip {
  75. color: #999999;
  76. padding-left: 30rpx;
  77. font-size: 24rpx;
  78. margin-bottom: 80rpx;
  79. }
  80. .button {
  81. background: #fea200;
  82. color: #fff;
  83. text-align: center;
  84. height: 88rpx;
  85. line-height: 88rpx;
  86. font-weight: 400;
  87. border-radius: 8rpx;
  88. }
  89. }
  90. </style>
  91. <style scoped>
  92. .container >>> .uni-easyinput__content-input {
  93. padding-left: 30rpx !important;
  94. padding-top: 10rpx;
  95. padding-bottom: 10rpx;
  96. }
  97. </style>