VueJS Syntax: Running method on mount
You should use mounted
event in following way with correct method declaration.
export default {
mounted() {
this.loadData();
},
methods: {
loadData() {
// This syntax may be wrong, too. But the function isn't
// even running, so I haven't started to debug this yet
this.$http.get("https://icanhazip.com")
.then(xhr => this.text = xhr.body);
}
}
};
More details can be found here.
https://vuejs.org/v2/api/#mounted
You need to use the v-on ( @ ) directive to listen to DOM events like click and run some function in methods in this way:
<button @click="loadData">Reload</button>
@Thusitha is correct for the mounted, you need to update it.