JavaScript/vue.js/调用其他组件的函数:修订间差异
来自康健生活
创建页面,内容为“== 引言 == 在被调用的方法所在的文件中,使用事件车注册事件。 {{hc|listLeft.vue|<syntaxhighlight lang="html"> <script> </script> </syntaxhi…” |
|||
| 第4行: | 第4行: | ||
{{hc|listLeft.vue|<syntaxhighlight lang="html"> | {{hc|listLeft.vue|<syntaxhighlight lang="html"> | ||
<script> | <script> | ||
mounted(){ | |||
const _self = this; | |||
EventBus.$on('searchInputChange', function (searchValue) { | |||
_self.renderRedirectSearch(searchValue); | |||
}) | |||
}, | |||
</script> | |||
</syntaxhighlight>}} | |||
在另一个页面类似如下调用 listLeft.vue 组件中的方法 | |||
{{hc|searchmodule.vue|<syntaxhighlight lang="html"> | |||
<script> | |||
inputValueChange () { | |||
if(this.$route.path === '/search') { | |||
EventBus.$emit('searchInputChange', this.searchValue); | |||
} | |||
} | |||
</script> | </script> | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||