index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <div class="login_box">
  3. <van-button type="info" @click="handleToast(0)">普通Toast</van-button>
  4. <van-button type="success" @click="handleToast(1)">成功Toast</van-button>
  5. <van-button type="danger" @click="handleToast(2)">失败Toast</van-button>
  6. <van-button type="danger" @click="showLoading">Loading</van-button>
  7. <br />
  8. <van-button plain @click="handleAlert">Alert</van-button>
  9. <van-button type="primary" plain @click="handleConfirm">Confirm</van-button>
  10. <van-button type="success" plain @click="handleNotify">Notify</van-button>
  11. <van-button type="info" plain @click="openHomePage">打开首页</van-button>
  12. <br />
  13. <h1>{{ getB }}</h1>
  14. </div>
  15. </template>
  16. <script>
  17. import { mapState, mapGetters } from 'vuex'
  18. import { toast, alert, confirm, notify } from '@/utils/toast'
  19. import Loading from '@/utils/loading'
  20. export default {
  21. name: 'Login',
  22. mounted() {
  23. this.handleVueX()
  24. this.handleMapState()
  25. this.handleMapGetters()
  26. },
  27. computed: {
  28. ...mapState(['base']),
  29. ...mapGetters('base', ['getB'])
  30. },
  31. methods: {
  32. showLoading() {
  33. Loading.show()
  34. setTimeout(() => {
  35. Loading.hide()
  36. }, 3000)
  37. },
  38. // toast
  39. handleToast(type) {
  40. toast('这是Toast提示', type)
  41. },
  42. // alert
  43. handleAlert() {
  44. alert('确认删除吗?')
  45. .then(() => {
  46. toast('你点了确认')
  47. })
  48. .catch(() => {
  49. toast('你点了关闭')
  50. })
  51. },
  52. // confirm
  53. handleConfirm() {
  54. confirm('是否确认删除?')
  55. .then(() => {
  56. toast('你点了确认')
  57. })
  58. .catch(() => {
  59. toast('你点了取消')
  60. })
  61. },
  62. // notify
  63. handleNotify() {
  64. notify('通知通知通知', 0)
  65. },
  66. // 新开页面
  67. openHomePage() {
  68. const path = this.$router.resolve({
  69. name: 'Home',
  70. query: {
  71. id: '123'
  72. }
  73. })
  74. window.open(path.href, '_blank')
  75. },
  76. // 去登陆页
  77. toHmoe() {
  78. this.$router.push({
  79. name: 'Login',
  80. query: {
  81. id: '123',
  82. type: 'edit'
  83. }
  84. })
  85. },
  86. // 使用vuex读取state
  87. handleVueX() {
  88. console.log(this.$store.state.base.b)
  89. },
  90. // 使用mapState映射vuex
  91. handleMapState() {
  92. console.log(this.base.b)
  93. },
  94. // 使用mapGetters映射getters
  95. handleMapGetters() {
  96. console.log(this.getB)
  97. }
  98. }
  99. }
  100. </script>
  101. <style scoped lang="scss">
  102. .login_box {
  103. padding: 20px;
  104. }
  105. </style>