JavaScript/vue.js/调用其他组件的函数

来自康健生活
Kangkk​(留言 | 贡献)2020年7月28日 (二) 06:05的版本 (→引言)

引言

在被调用的方法所在的文件中,使用事件车注册事件。

listLeft.vue
<script>
mounted(){
  const _self = this;
  EventBus.$on('searchInputChange', function (searchValue) {
    _self.renderRedirectSearch(searchValue);
  })
},
</script>

在另一个页面类似如下调用 listLeft.vue 组件中的方法

searchmodule.vue
<script>
inputValueChange () {
  if(this.$route.path === '/search') {
    EventBus.$emit('searchInputChange', this.searchValue);
  }
}
</script>