Quiz Entry - updated: 2026.06.20
How do you define methods in a Vue.js application?
You define functions in a methods object on the createApp config, where they access data via this.
<p>c = {{ c() }}</p>
<script>
Vue.createApp({
data() {
return { a: 3, b: 4 }
},
methods: {
c: function() {
return Math.sqrt(this.a ** 2 + this.b ** 2);
}
}
}).mount('#val');
</script>
Methods can access data properties via this. Call methods in templates with {{ methodName() }}.