JavaScript/vue.js/调用其他组件的函数:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
 
(未显示同一用户的1个中间版本)
第1行: 第1行:
== 引言 ==
== 引言 ==
先在 plugins 文件夹下新建 bus.js 文件实现事件车
{{hc|bus.js|<syntaxhighlight lang="javascript">
/*!
* @auther kangkk
* @desc 事件车
*/
import Vue from 'vue'
export default new Vue()</syntaxhighlight>}}
在被调用的方法所在的文件中,使用事件车注册事件。
在被调用的方法所在的文件中,使用事件车注册事件。


{{hc|listLeft.vue|<syntaxhighlight lang="html">
{{hc|listLeft.vue|<syntaxhighlight lang="html">
<script>
<script>
import EventBus from '@@/plugins/bus.js'
mounted(){
mounted(){
   const _self = this;
   const _self = this;
第17行: 第28行:
{{hc|searchmodule.vue|<syntaxhighlight lang="html">
{{hc|searchmodule.vue|<syntaxhighlight lang="html">
<script>
<script>
import EventBus from '@@/plugins/bus.js'
inputValueChange () {
inputValueChange () {
   if(this.$route.path === '/search') {
   if(this.$route.path === '/search') {