Problem Statement
What is a component in Vue.js and how do you create one?
Explanation
A component is a reusable, self-contained UI unit that bundles template, logic, and styles. Create a Single File Component (SFC) with <template>, <script>, and <style>. Register it locally or globally, then use its custom tag in templates.
Code Solution
SolutionRead Only
<template>
<div>
<h1>Hello, {{ message }}</h1>
</div>
</template>
<script>
export default {
name: 'MyComponent',
data() { return { message: 'Vue!' } }
}
</script>
<style scoped>
h1 { color: blue; }
</style>