Blogger Information
Blog 47
fans 0
comment 2
visits 102516
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
vue 兄弟组件间的传值方式
拾一枝樱花的博客
Original
589 people have browsed it

1.新建一个bus.js文件(可以使用一个空的Vue实例作为中央事件总线。)

  1. import Vue from 'vue'
  2. const Bus = new Vue()
  3. export default Bus

2.在组件1中引入

  1. bus.$on("自定义事件",val=>{
  2. //这是事件函数 一旦changeBgc事件被触发,就会执行这里的代码
  3. console.log(val)
  4. })

3.在组件2中引入

  1. bus.$emit("自定义事件", "red")
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post