SFC Syntax Specification
Overview
A Vue Single-File Component (SFC), conventionally using the *.vue
file extension, is a custom file format that uses an HTML-like syntax to describe a Vue component. A Vue SFC is syntactically compatible with HTML.
Each *.vue
file consists of three types of top-level language blocks: <template>
, <script>
, and <style>
, and optionally additional custom blocks:
vue
<template>
<div class="example">{{ msg }}</div>
</template>
<script>
export default {
data() {
return {
msg: 'Hello world!'
}
}
}
</script>
<style>
.example {
color: red;
}
</style>
<custom1>
This could be e.g. documentation for the component.
</custom1>
Language Blocks
<template>
Each
*.vue
file can contain at most one top-level<template>
block.Contents will be extracted and passed on to
@vue/compiler-dom
, pre-compiled into JavaScript render functions, and attached to the exported component as itsrender
option.