Three sections in Vue.js

These three sections are often encapsulated in a single file when using Vue's single-file component format.

<template>

The template section defines the structure of the component's HTML markup. This is where you specify the layout and structure of your component, and you can use Vue's template syntax to bind data and create dynamic content. Vue's template syntax allows you to use directives (e.g., v-bind, v-for, v-model) to bind data and control the rendering of HTML elements.

<script>

The script section is where you define the JavaScript logic for your component. You can define data, methods, computed properties, and lifecycle hooks in this section. The data represents the component's state, methods are functions that can be called from the template, computed properties are used to derive values based on the component's data, and lifecycle hooks allow you to respond to various events during the component's lifecycle.

<style>

The style section allows you to define the CSS styles for your component. You can use plain CSS or pre-processors like SASS or LESS. The styles defined in this section are scoped to the component, meaning they won't affect other components, thanks to the encapsulation provided by Vue's single-file component system.

Last updated