index.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <view>
  3. <Nav title="我的" :isBack="false" />
  4. <view class="user">
  5. <u-icon name="https://b.yzcdn.cn/vant/icon-demo-1126.png" size="100rpx" style="margin-bottom: 40rpx;" />
  6. <view class="user-name">
  7. {{userName}}
  8. </view>
  9. </view>
  10. <view class="btn">
  11. <u-button type="warning" text="退出登录" @click="show=true" size="large"></u-button>
  12. </view>
  13. <view>
  14. <u-modal :show="show" title="提示" content='是否退出登录?' showCancelButton @confirm="loginOut"
  15. @cancel="show=false"></u-modal>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. data() {
  22. return {
  23. //模态框
  24. show: false,
  25. };
  26. },
  27. computed: {
  28. userName() {
  29. return this.$store.getters.userName
  30. }
  31. },
  32. methods: {
  33. //退出登录
  34. loginOut() {
  35. this.$store.dispatch('user/logout').then(res => {
  36. if (res.data.code === 200) {
  37. uni.redirectTo({
  38. url: "/pages/login/index"
  39. })
  40. }
  41. })
  42. }
  43. }
  44. }
  45. </script>
  46. <style lang="scss" scoped>
  47. .user {
  48. display: flex;
  49. flex-direction: column;
  50. align-items: center;
  51. padding-top: 300rpx;
  52. }
  53. .user-name {
  54. font-weight: bold;
  55. }
  56. .btn {
  57. position: absolute;
  58. bottom: 100rpx;
  59. left: 0;
  60. right: 0;
  61. padding:0 80rpx;
  62. }
  63. </style>