script setup?Consider this Vue 3 component using <script setup> syntax. What will it display on the page?
<template>
<p>{{ message }}</p>
</template>
<script setup>
import { ref } from 'vue'
const message = ref('Hello from script setup!')
</script>Remember that ref creates a reactive variable and you can use it directly in the template.
The message variable is a ref holding the string. Vue unwraps ref values in templates, so it displays the string content.
script setup?Choose the correct way to define a reactive object named user with properties name and age inside <script setup>.
Use reactive for objects and ref for primitive values or single objects.
reactive wraps an object to make all its properties reactive. Option A correctly uses an object literal.
script setup component update the count?Look at this component code. Why doesn't the displayed count update?
<template>
<p>{{ count }}</p>
</template>
<script setup>
let count = 0
setInterval(() => {
count++
}, 1000)
</script>Think about how Vue tracks changes to update the template.
Variables declared as plain let are not reactive. Vue won't update the template when count changes. Using ref makes it reactive.
onMounted lifecycle hook in script setup?Which code snippet correctly runs a function when the component is mounted using <script setup>?
Remember script setup is a simpler syntax without explicit setup() function.
Option C correctly imports and calls onMounted directly in script setup. Option C is invalid because setup() is not used explicitly here.
<script setup> over traditional setup() function in Vue 3?Choose the best explanation for why <script setup> is preferred in many Vue 3 projects.
Think about how script setup simplifies component code.
<script setup> lets you write less code by skipping the explicit return statement and enables direct use of imports and reactive variables in templates.