Skip to content

Commit a7eeb5c

Browse files
committed
update: 修改$emit示例
1 parent 16565dd commit a7eeb5c

File tree

2 files changed

+48
-40
lines changed

2 files changed

+48
-40
lines changed

pages/API/navigator/navigator.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@
2626
navigateTo() {
2727
uni.navigateTo({
2828
url: 'new-page/new-vue-page-1?data=Hello'
29-
})
30-
setTimeout(()=>{
31-
uni.$emit('postMsg',{msg:'From navigator'})
32-
},1000)
29+
})
3330
},
3431
navigateBack() {
3532
uni.navigateBack();

pages/API/navigator/new-page/new-vue-page-2.vue

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,88 @@
11
<template>
2-
<view class="root">
3-
<view class="page-body">
2+
<view class="root">
3+
<view class="page-body">
44
<view class="new-page__color" @click="setColorIndex(colorIndex>1?0:colorIndex+1)" :style="{backgroundColor:currentColor}">
55
<text class="new-page__color-text">点击改变颜色</text>
66
</view>
77
<view class="new-page__text-box">
88
<text class="new-page__text">点击上方色块使用vuex在页面之间进行通讯</text>
99
</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>
1215
</template>
1316
<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']),
2228
...mapGetters(['currentColor'])
2329
},
24-
methods:{
25-
...mapMutations(['setColorIndex'])
30+
methods: {
31+
...mapMutations(['setColorIndex']),
32+
emitMsg() {
33+
uni.$emit('postMsg', {
34+
msg: 'From: Vue Page'
35+
})
36+
}
2637
}
27-
}
38+
}
2839
</script>
2940
<style>
30-
page{
31-
display: flex;
32-
min-height: 100%;
33-
}
41+
page {
42+
display: flex;
43+
min-height: 100%;
44+
}
3445
3546
.new-page__text {
3647
font-size: 14px;
3748
color: #666666;
3849
}
3950
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+
}
4556
46-
.page-body{
47-
flex: 1;
48-
display: flex;
57+
.page-body {
58+
flex: 1;
59+
display: flex;
4960
flex-direction: column;
50-
justify-content: flex-start;
51-
align-items: center;
61+
justify-content: flex-start;
62+
align-items: center;
5263
padding-top: 50px;
53-
}
64+
}
5465
55-
.new-page__text-box{
66+
.new-page__text-box {
5667
padding: 20px;
5768
}
5869
59-
.new-page__color{
70+
.new-page__color {
6071
display: flex;
6172
width: 200px;
6273
height: 100px;
63-
justify-content: center;
64-
align-items: center;
74+
justify-content: center;
75+
align-items: center;
6576
}
6677
67-
.new-page__color-text{
78+
.new-page__color-text {
6879
font-size: 14px;
6980
color: #FFFFFF;
7081
line-height: 30px;
7182
text-align: center;
7283
}
7384
74-
.new-page__button-item{
85+
.new-page__button-item {
7586
margin-top: 15px;
7687
width: 300px;
7788
}

0 commit comments

Comments
 (0)