new-vue-page-2.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <view class="root">
  3. <view class="page-body">
  4. <view class="new-page__color" @click="setColorIndex(colorIndex>1?0:colorIndex+1)" :style="{backgroundColor:currentColor}">
  5. <text class="new-page__color-text">点击改变颜色</text>
  6. </view>
  7. <view class="new-page__text-box">
  8. <text class="new-page__text">点击上方色块使用vuex在页面之间进行通讯</text>
  9. </view>
  10. <view class="new-page__button">
  11. <button class="new-page__button-item" @click="emitMsg">向上一页面传递数据</button>
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import {
  18. mapState,
  19. mapGetters,
  20. mapMutations
  21. } from 'vuex'
  22. export default {
  23. data() {
  24. return {}
  25. },
  26. computed: {
  27. ...mapState(['colorIndex', 'colorList']),
  28. ...mapGetters(['currentColor'])
  29. },
  30. methods: {
  31. ...mapMutations(['setColorIndex']),
  32. emitMsg() {
  33. uni.$emit('postMsg', {
  34. msg: 'From: Vue Page'
  35. })
  36. }
  37. }
  38. }
  39. </script>
  40. <style>
  41. .new-page__text {
  42. font-size: 14px;
  43. color: #666666;
  44. }
  45. .root {
  46. display: flex;
  47. flex: 1;
  48. flex-direction: column;
  49. }
  50. .page-body {
  51. flex: 1;
  52. display: flex;
  53. flex-direction: column;
  54. justify-content: flex-start;
  55. align-items: center;
  56. padding-top: 50px;
  57. }
  58. .new-page__text-box {
  59. padding: 20px;
  60. }
  61. .new-page__color {
  62. display: flex;
  63. width: 200px;
  64. height: 100px;
  65. justify-content: center;
  66. align-items: center;
  67. }
  68. .new-page__color-text {
  69. font-size: 14px;
  70. color: #FFFFFF;
  71. line-height: 30px;
  72. text-align: center;
  73. }
  74. .new-page__button-item {
  75. margin-top: 15px;
  76. width: 300px;
  77. }
  78. </style>