KoderSolutionKoderSolution LogoKoderSolution Logo
HomeArticlesTutorialsToolsRun CodeForumAI Lab
🖖

Vue

Topic Hub & Articles

Vue Intro

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Get Started

10 min

Vue Directives

10 min

Vue Events

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Forms

10 min

Vue Components

10 min

Vue Props

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Methods

10 min

Vue Computed Properties

10 min

Vue Watchers

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Class and Style Bindings

10 min

Vue Conditional Rendering

10 min

Vue List Rendering

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Template Syntax

10 min

Vue Teleport

10 min

Vue Suspense

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Transitions

10 min

Vue Mixins

10 min

Vue Custom Directives

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Plugins

10 min

Vue Slots

10 min

Vue Provide / Inject

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Dynamic Components

10 min

Vue Async Components

10 min

Composition API Intro

10 min

Recap Quiz

Gated

Milestone Assessment

ref vs reactive

10 min

Lifecycle Hooks

10 min

Dependency Injection

10 min

Recap Quiz

Gated

Milestone Assessment

Computed and Watch

10 min

Template Refs

10 min

Composable Functions

10 min

Script Setup

10 min

Progress
0%

0 / 32 Lessons

KoderSolutionKoderSolution LogoKoderSolution Logo

The world’s most advanced technical ecosystem for modern software engineers. Learn, build, and grow with next-generation developer tools and resources.

Facebook PageX (Twitter) ProfileYouTube ChannelContact Support

Engineering Newsletter

Subscribe for weekly software engineering tutorials, architecture guides, and developer tool updates.

Platforms

  • Technical Articles
  • Interactive Tutorials
  • AI Coding Lab
  • Developer Forum
  • Developer Tools

Pages

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of Service
  • Refund Policy
  • Disclaimer
  • Advertisement

Popular Topics

  • PHP
  • Laravel
  • Python
  • React.Js
  • MySQL
© 2026 KoderSolutionAll Rights Reserved
Developed Bymaksudur.dev
VueVue Tutorial
Lesson

Vue Methods

10 min reading
Free Course

Vue Methods: Defining Handlers and Functions in Script Setup

Vue methods are functions inside your component that handle user actions, update reactive state, or trigger network requests. In Vue 3 <script setup>, methods are simply regular JavaScript functions declared at the top level.

Unlike the legacy Options API, <script setup> removes the methods object and this binding completely. You read and update refs directly inside normal functions, which makes refactoring and TypeScript checking much cleaner.

flowchart TD
    Template["User Click or Submit"] --> Method["Script Setup Function"]
    Method --> Mutation["Update Reactive Refs"]
    Method --> Effect["Run API or Side Effect"]

Methods vs Computed Properties

  • Use Methods for actions that happen when events fire, such as adding items, submitting forms, or deleting records.
  • Use Computed Properties for derived values displayed in the template, because computed values cache results until dependencies change.

Practical Method Handler SFC Example

This task list component declares addItem and removeItem inside <script setup> and binds both functions to template events.

<script setup>
import { ref } from 'vue';

const items = ref(['Vue 3', 'Vite', 'Pinia']);
const newItem = ref('');

function addItem() {
  const trimmed = newItem.value.trim();
  if (!trimmed) return;

  items.value.push(trimmed);
  newItem.value = '';
}

function removeItem(index) {
  items.value.splice(index, 1);
}
</script>

<template>
  <div class="list-manager">
    <div class="input-row">
      <input
        v-model="newItem"
        @keyup.enter="addItem"
        placeholder="Add technology..."
      />
      <button @click="addItem">Add</button>
    </div>

    <ul>
      <li v-for="(item, index) in items" :key="item">
        <span>{{ item }}</span>
        <button @click="removeItem(index)">Delete</button>
      </li>
    </ul>
  </div>
</template>

Common Mistakes

  • Calling Expensive Functions in Mustache Expressions: Calling {{ formatHeavyList() }} inside <template> re-runs that function on every component re-render. Move pure calculations into computed() instead.
  • Using Arrow Functions in Options API: If you maintain older Options API code, never define methods with arrow functions because arrow functions lose access to this. In <script setup>, both function declarations and arrow functions work fine.
  • Forgetting .value Inside Functions: Methods inside <script setup> must mutate items.value, not items, to keep reactivity working.

Frequently Asked Questions

Can methods in <script setup> be async?

Yes. You can write async function fetchUsers() inside <script setup> and bind @click="fetchUsers" directly in the template.

Can I extract shared methods into another file?

Yes. Move reusable functions and reactive state into a composable file like composables/useItems.js and import them into any component.

Do I need to return methods from <script setup>?

No. Every top-level function declared inside <script setup> is exposed to the <template> automatically at compile time.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Related Developer Tools & Topic Hub

Vue Topic Hub
JSON Formatter
Validate and format JSON payloads
HTML Formatter
Format HTML templates
CSS Formatter
Clean and format stylesheets
All Vue Articles
Deep-dive guides, tips & discussions
PreviousVue Props
Continue JourneyNext: Vue Computed Properties

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum