Setup function basics
📖 Scenario: You are building a simple Vue 3 component that shows a greeting message. You will use the <script setup> to define the component's data.
🎯 Goal: Create a Vue 3 component using the Composition API with <script setup> that defines a reactive variable message with the value 'Hello, Vue!'. The message will be automatically available for use in the template.
📋 What You'll Learn
Use the Composition API with
<script setup>Import and use
ref from 'vue'Create a reactive variable called
message with the exact value 'Hello, Vue!'Make the
message variable available to the template (automatic in <script setup>)Use the
message variable in the template with interpolation💡 Why This Matters
🌍 Real World
Vue 3's <code><script setup></code> is the modern way to write components. It helps organize code clearly and makes it easier to manage reactive data.
💼 Career
Understanding the <code><script setup></code> and Composition API is essential for modern Vue development jobs, as many projects use this pattern for better scalability and maintainability.
Progress0 / 4 steps