editUser.vue 1.8 KB

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