JavaScript/vue.js/兄弟组件的值:修订间差异
来自康健生活
创建页面,内容为“== 子传父,父传子 == == vuex == == eventBus == {{hc|eventBus.js|<syntaxhighlight lang="javascript"> Insert comment here </syntaxhighlight>}}” |
|||
| 第3行: | 第3行: | ||
== eventBus == | == eventBus == | ||
{{hc|eventBus.js|<syntaxhighlight lang="javascript"> | {{hc|eventBus.js|<syntaxhighlight lang="javascript"> | ||
import Vue from 'vue' | |||
export default new Vue() | |||
</syntaxhighlight>}} | |||
{{hc|AllCountry.vue|<syntaxhighlight lang="javascript"> | |||
import EventBus from "@/router/eventBus"; | |||
... | |||
methods:{ | |||
allCountryEvent() { | |||
EventBus.$emit('allCountry', { | |||
isCountry: this.isCountry, | |||
isDepartment: this.isDepartment, | |||
isCountryValue: this.isCountryValue, | |||
isDepartmentValue: this.isDepartmentValue, | |||
}) | |||
} | |||
} | |||
... | |||
</syntaxhighlight>}} | |||
{{hc|HoptialList.vue|<syntaxhighlight lang="javascript"> | |||
import EventBus from "@/router/eventBus"; | |||
... | |||
methods:{ | |||
eventBus.$on('allCountry',(message)=>{ | |||
console.log(message) | |||
}) | |||
... | |||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||