轻量事件总线
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
<template>
|
<template>
|
||||||
<button @click="decrease()">decrease</button>
|
<button @click="decrease()">-</button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import {EventBus} from '@/globalBus';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "brother",
|
name: "brother",
|
||||||
data() {
|
data() {
|
||||||
@@ -13,7 +15,7 @@
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
decrease() {
|
decrease() {
|
||||||
this.$EventBus.$emit("decreased", {
|
EventBus.$emit("decreased", {
|
||||||
num: this.num,
|
num: this.num,
|
||||||
deg: this.deg
|
deg: this.deg
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<button @click="increment()">increment</button>
|
<button @click="increment()">+</button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import {EventBus} from '@/globalBus';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "sister",
|
name: "sister",
|
||||||
data() {
|
data() {
|
||||||
@@ -15,7 +17,7 @@
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
increment() {
|
increment() {
|
||||||
this.$EventBus.$emit("incremented", {
|
EventBus.$emit("incremented", {
|
||||||
num: this.num,
|
num: this.num,
|
||||||
deg: this.deg
|
deg: this.deg
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import router from './router'
|
|||||||
import store from './store'
|
import store from './store'
|
||||||
|
|
||||||
Vue.config.productionTip = false
|
Vue.config.productionTip = false
|
||||||
Vue.prototype.$EventBus = new Vue()
|
// Vue.prototype.$EventBus = new Vue()
|
||||||
|
|
||||||
new Vue({
|
new Vue({
|
||||||
router,
|
router,
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import Brother from "../components/brother";
|
import Brother from "../components/brother";
|
||||||
import Sister from "../components/sister";
|
import Sister from "../components/sister";
|
||||||
|
import {EventBus} from '@/globalBus';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -42,14 +43,14 @@
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.$EventBus.$on("incremented", ({num, deg}) => {
|
EventBus.$on("incremented", ({num, deg}) => {
|
||||||
this.fontCount += num
|
this.fontCount += num
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.backCount += num
|
this.backCount += num
|
||||||
this.degValue += deg;
|
this.degValue += deg;
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
this.$EventBus.$on("decreased", ({num, deg}) => {
|
EventBus.$on("decreased", ({num, deg}) => {
|
||||||
this.fontCount -= num
|
this.fontCount -= num
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.backCount -= num
|
this.backCount -= num
|
||||||
|
|||||||
Reference in New Issue
Block a user