user.vue 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <template>
  2. <view class="content">
  3. <view class="btn-row">
  4. <button v-if="!hasLogin" type="primary" class="primary" @tap="bindLogin">登录</button>
  5. <button v-if="hasLogin" type="default" @tap="bindLogout">退出登录</button>
  6. </view>
  7. </view>
  8. </template>
  9. <script>
  10. import {
  11. mapState,
  12. mapMutations
  13. } from 'vuex'
  14. export default {
  15. computed: {
  16. ...mapState(['hasLogin', 'forcedLogin'])
  17. },
  18. methods: {
  19. ...mapMutations(['logout']),
  20. bindLogin() {
  21. uni.navigateTo({
  22. url: '../login/login',
  23. });
  24. },
  25. bindLogout() {
  26. this.logout();
  27. /**
  28. * 如果需要强制登录跳转回登录页面
  29. */
  30. if (this.forcedLogin) {
  31. uni.reLaunch({
  32. url: '../login/login',
  33. });
  34. }
  35. }
  36. }
  37. }
  38. </script>
  39. <style>
  40. </style>