avatar.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <view>
  3. <u-cell-group>
  4. <u-cell-item title="头像" @click="editAvatar">
  5. <image :src="avatarUrl" class="avatar"></image>
  6. </u-cell-item>
  7. <u-cell-item title="昵称" value="李宏杰" @click="editNickName"></u-cell-item>
  8. </u-cell-group>
  9. <u-modal v-model="show" :show-cancel-button="true" title="修改昵称">
  10. <view class="slot-content">
  11. <u-input v-model="value" />
  12. </view>
  13. </u-modal>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. data() {
  19. return {
  20. show: false,
  21. avatarUrl:'/static/avatar.png',
  22. value: '李宏杰',
  23. }
  24. },
  25. onLoad(option) {
  26. },
  27. onShow(){
  28. },
  29. methods: {
  30. editNickName(){
  31. this.show = true
  32. },
  33. editAvatar(){
  34. let that = this
  35. uni.chooseImage({
  36. count: 1, //默认9
  37. sizeType: [ 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  38. success: function (res) {
  39. that.avatarUrl = res.tempFilePaths[0]
  40. }
  41. });
  42. }
  43. },
  44. }
  45. </script>
  46. <style scope>
  47. .slot-content{
  48. margin: 30rpx;
  49. color: #606266;
  50. }
  51. .avatar{
  52. height: 70rpx;
  53. width: 70rpx;
  54. }
  55. page {
  56. background: #FFFFFF;
  57. }
  58. </style>