Step 1: Establish bus file component communication

  • Write a bus.js file under the folder and write the following code
// bus.js
import Vue from 'vue' 
export default new Vue()
Copy the code

Step 2: Set up bus file to send

// Introduce a public bus
import Bus from '.. /.. /api/bus' 
// Lifecycle functions
created(){
    Bus.$emit('val', the value to be passed)console.log('I sent it.');
 },
Copy the code

Step 3: Set up bus file reception

import Bus from '.. /.. /api/bus'
created(){ 
     // Use the $on event to receive parameters
     Bus.$on('val'.(data) = > {
     console.log(data) 
  })
 }
Copy the code