Chapter 88: Vue ‘methods’ Option

The methods option

This is the original, classic way to define functions (methods) inside a Vue component — the way Vue worked from the very beginning (Vue 1 → Vue 2 → early Vue 3), and the way millions of legacy projects, tutorials, job interview questions, and old Stack Overflow answers still use it in 2026.

Even if you personally write only <script setup> + Composition API today (which is the modern recommendation), you must understand the methods option properly because:

  • You will read/maintain old code written this way
  • Many job interviews (especially in India) still ask about it
  • Some advanced patterns (mixins, plugins, global components) are still written using Options API
  • Vue Devtools still shows methods in this format

So let’s go through it step by step — like I’m pair-programming with you and explaining both the old world and why we mostly moved away from it.

1. What is the methods option? (Very simple mental model)

methods is a plain object where each key is the name of a function, and each value is the function itself.

Vue takes this object and attaches all those functions to the component instance, so you can call them from the template or from other methods using this.methodName().

JavaScript

After Vue processes this:

  • this.increment() becomes available everywhere in the component
  • You can write @click=”increment” in the template
  • All this inside methods refers to the component instance (has access to this.data, this.computed, this.$refs, etc.)

2. Real, Complete Example – Todo List with Methods

vue

3. Important Rules & Gotchas (2026 Must-Know)

Rule / Gotcha Correct Behavior / Best Practice
methods must be an object methods: { increment() { … } } — never an array or function
All methods get this bound automatically this inside methods = component instance (access this.count, this.$refs, etc.)
Can call other methods Yes — this.resetAndNotify() calls this.clearAll() and this.notify()
Can be async Yes — async fetchUser() { await … } works perfectly
Can be called from template Yes — @click=”increment”, @keyup.enter=”submit”
Arrow functions? Avoid — increment: () => {} loses this binding → this becomes undefined
Can I define computed-like logic? No — use computed for cached values; methods are for actions
Still used in 2026? Yes — in legacy code, some plugins, interviews, but not in new <script setup> code

4. Modern Vue 3 – Why We Almost Never Use methods Anymore

In <script setup> (the 2026 standard):

vue

→ No methods object → No this → Functions are just normal JavaScript at the top level → Same power, much cleaner & type-safe with TypeScript

Quick Summary Table – methods in 2026

Question Options API (legacy) Composition API (<script setup>) What you should do in new code
How to define functions? methods: { increment() { … } } normal function increment() { … } Composition API
Access in template @click=”increment” @click=”increment”
Access inside function this.count count.value
Still used in 2026? Yes — in legacy code, some plugins, interviews Almost never (except legacy migration) Avoid unless maintaining old code
TypeScript friendly? Poor Excellent (normal functions + types) Use Composition

Final 2026 Advice from Real Projects

  • In new projects → you should never write methods: { … } — just define functions at the top level in <script setup>
  • When you see methods → it means Options API (legacy style)
  • Learn to read Options API — many jobs, open-source projects, tutorials still use it
  • Never teach beginners methods as primary — start with normal functions in <script setup>
  • If migrating old code → gradually convert methods → normal functions, data() → ref / reactive, etc.

Your mini homework:

  1. Create the todo component above in Options API
  2. Click buttons → see methods work with this
  3. Console.log this inside a method → see the component instance
  4. Convert it to <script setup> → compare readability & TypeScript support

Any part confusing? Want to see:

  • Full Options API vs Composition API side-by-side project?
  • How methods looks in Vue Devtools?
  • Common bugs when using arrow functions in methods?
  • Real component written in both styles?

Just tell me — we’ll convert and compare together step by step 🚀

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *