Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

call vue function at element load

//At template:
<element id="my-element" :key="elementKey" @load="foo()">Hello, World!!</element>

//At script:
data() {
	return {
		elementKey: 0
	}
},

methods: {
	foo() {
    	//Do something.
    },
     
    bar() { //Call bar() whenever you want to make sure my-element reloads.
    	this.elementKey++
    }
}

/* NOTE:
	foo() will run whenever my-element loads, and bar() will
    make my-element reload.
    
    For example, you might want my-element to reload whenever
    a button is clicked. Then, just add @click="bar()" to that button.
*/
 
PREVIOUS NEXT
Tagged: #call #vue #function #element #load
ADD COMMENT
Topic
Name
8+2 =