index.vue 1.2 KB

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