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
MySQL is a multi-user managed database that can a...
The specific steps of installing mysql5.7.18 unde...
Table of contents 1 redis configuration file 2 Do...
MySQL binlog is a very important log in MySQL log...
Table of contents 1. What is a closure? 1.2 Memoi...
Master-slave synchronization, also called master-...
Load balancing is a commonly used device in serve...
Table of contents Step 1: Log in as root user. St...
1. Introduction The requirement is to obtain the ...
A style sheet describes how a document should be ...
A simple calculator written in WeChat applet for ...
This article shares the specific code of js to im...
Table of contents 1. v-text text rendering instru...
Ubuntu 20.04 does not have root login enabled by ...
Table of contents Overview 1. useState 1.1 Three ...