Vue3 Template Tag <template> | Rookie Tutorial
Rookie Tutorial --
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
Vue3 Tutorial
- Vue3 Tutorial
- Vue3 Introduction
- Vue3 Installation
- VSCode Vue
- Vue3 Build
- Vue3 Create Project
- Vue3 Project Introduction
- Vite Tutorial
- Vue3 Directory Structure
- Vue3 Getting Started
- Vue3 Basic Syntax
- Vue3 Declarative Rendering
- Vue3 Directives
- Vue3 Template Syntax
- Vue3 Conditional Statements
- Vue3 Loop Statements
- Vue3 Components
- Vue3 Computed Properties
- Vue3 Watch Properties
- Vue3 Style Binding
- Vue3 Event Handling
- Vue3 Forms
- Vue3 Custom Directives
- Vue3 Routing
- Vue3 Mixins
- Vue3 Ajax(axios)
- Vue3 Composition API
- Vue3 Single File Components
- Vue3 Pinia
Reference Manual
- Vue3 Built-in Attributes
- Vue3 Built-in Components
- Vue Component Instance
- Vue3 Built-in Directives
- Vue Instance Options
- Vue3 Lifecycle Hooks
- Vue3 Tailwind CSS
- Vue3 Global API
- Vue3 Options API
- Vue3 Quiz
Practical Case 1
- Vue3 Task Management System
- Environment Setup
- Core Business Development
- Component Splitting
- State Management and Data Persistence
- Routing System
- Logic Reuse and Performance Optimization
- Project Deployment
Practical Case 2
- Vue3 Blog Project
- Template Syntax Rendering
- Reactive Data
- Component Splitting
- Routing Navigation
- Lifecycle and Data Requests
- watch and Search Functionality
- Composable β Encapsulating Reusable Logic
- Pinia β Global State Management
- Build and Deploy β Deploy to Vercel
Deep Exploration
Web Design and Development
Programming Languages
Web Services
Development Tools
Programming
Scripting Languages
Scripts
Computer Science
Web Service
Software
Vue3 Template Tag <template>
In Vue3, the <template> tag is a very core concept.
<template> is used to define the template structure of a component and is the foundation for Vue to render pages.
Basic Concepts of <template> Tag
The <template> tag is used in Vue3 to define component templates. It itself will not be rendered to the final DOM, but serves as a container for wrapping Vue's template syntax (such as interpolation, directives, etc.). Vue will generate actual HTML structure based on the content in <template>.
Features
- Non-rendering tag: The
<template> tag itself will not appear in the final DOM structure.
- Template container: It is used to wrap Vue's template syntax, such as interpolation, conditional rendering, list rendering, etc.
- Supports multiple root nodes: In Vue3, the
<template> tag can contain multiple root nodes, while in Vue2 only one was allowed.
Usage Scenarios of <template> Tag
1. Defining Component Templates
In Single File Components (.vue files), the <template> tag is used to define the template part of the component. For example:
Example
<template>
<div>
<h1>{{ title }}</h1>
<p>{{ description }}</p>
</div>
</template>
<script>
export default {
data() {
return {
title: "Hello Vue3",
description: "This is a Vue3 template example."
};
}
};
</script>
2. Conditional Rendering
The <template> tag can be used with v-if or v-else directives to achieve conditional rendering. For example:
Example
<template>
<div>
<template v-if="isVisible">
<p>This content is visible.</p>
</template>
</div>
</template>
<template><template> tag is a very core concept.<template> is used to define the template structure of a component and is the foundation for Vue to render pages.<template> Tag<template> tag is used in Vue3 to define component templates. It itself will not be rendered to the final DOM, but serves as a container for wrapping Vue's template syntax (such as interpolation, directives, etc.). Vue will generate actual HTML structure based on the content in <template>.<template> tag itself will not appear in the final DOM structure.<template> tag can contain multiple root nodes, while in Vue2 only one was allowed.<template> Tag.vue files), the <template> tag is used to define the template part of the component. For example:<template>
<div>
<h1>{{ title }}</h1>
<p>{{ description }}</p>
</div>
</template>
<script>
export default {
data() {
return {
title: "Hello Vue3",
description: "This is a Vue3 template example."
};
}
};
</script><template> tag can be used with v-if or v-else directives to achieve conditional rendering. For example:<template>
<div>
<template v-if="isVisible">
<p>This content is visible.</p>
</template>
</div>
</template>
YouTip