editName.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <view class="edit-name">
  3. <input class="input" type="nickname" placeholder="修改昵称" v-model="nickname" />
  4. <button class="save" @click="updateNickname">保存</button>
  5. </view>
  6. </template>
  7. <script>
  8. import {updateNickname} from '@/api/common.js'
  9. import { nextTick } from 'process'
  10. export default {
  11. data() {
  12. return {
  13. nickname:'',
  14. userId:'',
  15. userInfo:null
  16. }
  17. },
  18. methods: {
  19. // 修改昵称
  20. updateNickname() {
  21. if(!this.nickname){
  22. return uni.showToast({
  23. title:'昵称不能为空'
  24. })
  25. }
  26. updateNickname({nickname:this.nickname,userId:this.userId}).then(res=>{
  27. if(res.msg == '成功'){
  28. uni.showToast({
  29. title:'修改成功'
  30. })
  31. this.userInfo.nickname = this.nickname
  32. uni.setStorageSync('userInfo',JSON.stringify(this.userInfo))
  33. // uni.switchTab({
  34. // url:'../../pages/my/index'
  35. // })
  36. }
  37. })
  38. }
  39. },
  40. onLoad() {
  41. this.userInfo = JSON.parse(uni.getStorageSync('userInfo'))
  42. this.nickname = this.userInfo.nickname
  43. this.userId = this.userInfo.userId
  44. }
  45. }
  46. </script>
  47. <style lang="scss" scoped>
  48. .edit-name{
  49. .input{
  50. height: 80rpx;
  51. line-height: 180rpx;
  52. border-bottom: 1px solid #f1f1f1;
  53. padding-left: 60rpx;
  54. }
  55. .save{
  56. width: 450rpx;
  57. line-height: 110rpx;
  58. border-radius: 55rpx;
  59. margin-top: 50rpx;
  60. }
  61. }
  62. </style>