I am new to Vue, and there's something very basic I cannot figure out.
How a single file Vue component can call a method of itself in javascript code?
How a single file parent component can call a method of child in a javascript code?
Many similar questions were asked like herebut they all give an example of creating the Vue main application object. In my case it is hidden in the main.js of the generated boilerplate code which I assume should stay intact (the assumption may be wrong of cause).
Given the following simple template from Vue tutorial, - how can I call the doStuff method inside the javascript code (it appears to be undefined though it works as a click handler) - how can i call the HelloWorld methods.?:-
<template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld ref="foo" msg="Welcome to Your Vue.js App"/>
<a @click="doStuff()">Click me!</a> <!-- HERE IT WORKS -->
</div>
</template>
<script>
import HelloWorld from './components/HelloWorld.vue'
export default {
name: 'app',
components: {
HelloWorld
},
methods: {
doStuff: function doStuff () {
alert(this.$refs.foo.DoStuff); // THIS WORKS
}
}
}
window.onload = function(e){
alert(doStuff); // DO STUFF IS UNDEFINED
}
</script>