new-vue-page-1.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view class="root">
  3. <page-head :title="title"></page-head>
  4. <view class="page-body">
  5. <view class="new-page__text-box">
  6. <text class="new-page__text">从上个页面接收到参数:{{data}}</text>
  7. </view>
  8. <view class="new-page__color" @click="setColorIndex(colorIndex>1?0:colorIndex+1)" :style="{backgroundColor:currentColor}">
  9. <text class="new-page__color-text">点击改变颜色</text>
  10. </view>
  11. <view class="new-page__text-box">
  12. <text class="new-page__text">点击上方色块使用vuex在页面之间进行通讯</text>
  13. </view>
  14. <view class="new-page__button">
  15. <!-- #ifndef VUE3-->
  16. <button class="new-page__button-item" @click="navToNvue">跳转NVUE页面</button>
  17. <!-- #endif -->
  18. <button class="new-page__button-item" @click="navToVue">跳转VUE页面</button>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import {mapState,mapGetters,mapMutations} from 'vuex'
  25. export default {
  26. data() {
  27. return {
  28. title: '新页面',
  29. data:""
  30. }
  31. },
  32. computed:{
  33. ...mapState(['colorIndex','colorList']),
  34. ...mapGetters(['currentColor'])
  35. },
  36. onLoad(e){
  37. if(e.data){
  38. this.data = e.data;
  39. }
  40. uni.$on('postMsg',(res)=>{
  41. uni.showModal({
  42. content: `收到uni.$emit消息:${res.msg}`,
  43. showCancel: false
  44. })
  45. })
  46. },
  47. onUnload() {
  48. uni.$off('postMsg')
  49. },
  50. methods:{
  51. ...mapMutations(['setColorIndex']),
  52. navToNvue(){
  53. uni.navigateTo({
  54. url:'new-nvue-page-1'
  55. })
  56. },
  57. navToVue(){
  58. uni.navigateTo({
  59. url:'new-vue-page-2'
  60. })
  61. }
  62. }
  63. }
  64. </script>
  65. <style>
  66. .new-page__text {
  67. font-size: 14px;
  68. color: #666666;
  69. }
  70. .root{
  71. display: flex;
  72. flex: 1;
  73. flex-direction: column;
  74. }
  75. .page-body{
  76. /* flex: 1; */
  77. display: flex;
  78. flex-direction: column;
  79. justify-content: flex-start;
  80. align-items: center;
  81. }
  82. .new-page__text-box{
  83. padding: 20px;
  84. }
  85. .new-page__color{
  86. display: flex;
  87. width: 200px;
  88. height: 100px;
  89. justify-content: center;
  90. align-items: center;
  91. }
  92. .new-page__color-text{
  93. font-size: 14px;
  94. color: #FFFFFF;
  95. line-height: 30px;
  96. text-align: center;
  97. }
  98. .new-page__button-item{
  99. margin-top: 15px;
  100. width: 300px;
  101. }
  102. </style>