Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

one component to another component in vuejs trigger function

For non-parent-child relation, then this is the same as this one. Call one method, apparently any method of a component from any other component. Just add a $on function to the $root instance and call form any other component accessing the $root and calling $emit function.

On First component

    ....
    mounted() {
        this.$root.$on('component1', () => {
            // your code goes here
            this.c1method()
        }
    }
                       
and in the second component call the $emit function in $root

    ...
    c2method: function(){
     this.$root.$emit('component1') //like this
    },
It acts more like a socket. Reference here

https://stackoverflow.com/a/50343039/6090215
Comment

PREVIOUS NEXT
Code Example
Javascript :: set embed color discord.js 
Javascript :: js format indian price with commas 
Javascript :: paragraph to single line in javascript 
Javascript :: js how to see console day tomorrow 
Javascript :: express prisma 
Javascript :: update in mongoose node js 
Javascript :: js html editor 
Javascript :: quiz javascript example with array 
Javascript :: js get screen width 
Javascript :: javascript for...of with Strings 
Javascript :: sanitize html in javascript 
Javascript :: how to find last element of an array 
Javascript :: jest mock mockname 
Javascript :: video conferencing app with html and js 
Javascript :: jquery validate on keyup 
Javascript :: math.floor 
Javascript :: doughnut chartjs with react display percentage 
Javascript :: perent to child data pass in angular 
Javascript :: how to get variable from url in javascript 
Javascript :: javascript insertion sort 
Javascript :: what is $ in jquery 
Javascript :: mongoose use unified topology 
Javascript :: how to subtract time in javascript 
Javascript :: write hover animation for styled div 
Javascript :: node js version 14 
Javascript :: event property value in angular 
Javascript :: js join two arrays 
Javascript :: js filter 
Javascript :: apollo client nextjs 
Javascript :: nodejs import readline 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =