A single-file component (SFC) keeps a frontend component’s markup, styles, and JavaScript together in one file. This makes the component’s view and interaction logic easier to inspect as one unit. section 1.3.1
A component file brings together:
- HTML or an HTML-like template for the view. section 1.3.1
- CSS for presentation. section 1.3.1
- JavaScript for interaction and application behavior. section 1.3.1
Conditional content
A component can show a paragraph only when application state indicates a discount. Vue uses v-if, Svelte uses an if block, and React uses a JavaScript expression. section 1.3.1
<p v-if="hasDiscount"> You get a discount! </p>
See the Vue conditional-rendering example; comparable Svelte and React forms are available as related listings. section 1.3.1
