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