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"]
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>
{{ formatHeavyList() }} inside <template> re-runs that function on every component re-render. Move pure calculations into computed() instead.methods with arrow functions because arrow functions lose access to this. In <script setup>, both function declarations and arrow functions work fine..value Inside Functions: Methods inside <script setup> must mutate items.value, not items, to keep reactivity working.<script setup> be async?Yes. You can write async function fetchUsers() inside <script setup> and bind @click="fetchUsers" directly in the template.
Yes. Move reusable functions and reactive state into a composable file like composables/useItems.js and import them into any component.
<script setup>?No. Every top-level function declared inside <script setup> is exposed to the <template> automatically at compile time.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With