Simple use of Vue busScenario description: Component A includes components B and C, and component B includes component D. What if component D wants to trigger the method of component C in component A? Of course there are solutions, you can use as follows: The emit of the bus is triggered in the D component, and then the on of the bus is used to trigger the method in the A component; In component D dataLoad(){ console.log('Loading complete trigger event'); this.$bus.$emit('itemDataLoad') // this.$bus.$emit('event name', parameter) // The second one can be a parameter}, In component A mounted() { // Listen for data loading in item this.$bus.$on('itemDataLoad', () => { console.log('Data loading completed'); }) // this.$bus.$on('event name', callback function (parameters)) }, Of course, in component A, events in component C can be triggered by Another step is that Don't worry, add $bus in main.js; // bus bus vue instance Vue.prototype.$bus = new Vue() Of course, the bus can be removed during the life cycle; this.$bus.$off(); Record encapsulated anti-shake function // debounce function: function (fun, delay) { let timer = null // Receive the value of the parameter passed in when calling the function... args can be multiple return function (...args) { if (tiemr) return timer = setTimeout(() => { fun.apply(this, args) }, delay); } } const refresh = debounce(xxx, 500) refresh('parameter 1', 'parameter 2', 'parameter 3') This is the end of this article about the simple use of Vue's bus. For more relevant content about the simple use of Vue's bus, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: How to Install Xrdp Server (Remote Desktop) on Ubuntu 20.04
>>: MySql COALESCE function usage code example
We will install phpMyAdmin to work with Apache on...
Preface The database deadlocks I encountered befo...
Reference: MySQL character set summary utf8mb4 ha...
The Linux stream editor is a useful way to run sc...
As a Vue user, it's time to expand React. Fro...
Table of contents How to install and configure To...
MySQL batch insert problem When developing a proj...
Library Management Create a library create databa...
This article describes the example of MySQL sched...
This article shares the specific code of JavaScri...
2D transformations in CSS allow us to perform som...
1. Download the installation package -Choose the ...
1. Background The following two problems are enco...
The difference between := and = = Only when setti...
Table of contents Preface Project Design rear end...