Skip to content

Commit b524a89

Browse files
authored
Update introduction.md
1 parent 5de2d11 commit b524a89

File tree

1 file changed

+0
-281
lines changed

1 file changed

+0
-281
lines changed

src/guide/introduction.md

Lines changed: 0 additions & 281 deletions
Original file line numberDiff line numberDiff line change
@@ -1,282 +1 @@
1-
---
2-
footer: false
3-
---
41

5-
# Introduction {#introduction}
6-
7-
:::info You are reading the documentation for Vue 3!
8-
9-
- Vue 2 support has ended on **Dec 31, 2023**. Learn more about [Vue 2 EOL](https://v2.vuejs.org/eol/).
10-
- Upgrading from Vue 2? Check out the [Migration Guide](https://v3-migration.vuejs.org/).
11-
:::
12-
13-
<style src="@theme/styles/vue-mastery.css"></style>
14-
<div class="vue-mastery-link">
15-
<a href="https://www.vuemastery.com/courses/" target="_blank">
16-
<div class="banner-wrapper">
17-
<img class="banner" alt="Vue Mastery banner" width="96px" height="56px" src="https://storage.googleapis.com/vue-mastery.appspot.com/flamelink/media/vuemastery-graphical-link-96x56.png" />
18-
</div>
19-
<p class="description">Learn Vue with video tutorials on <span>VueMastery.com</span></p>
20-
<div class="logo-wrapper">
21-
<img alt="Vue Mastery Logo" width="25px" src="https://storage.googleapis.com/vue-mastery.appspot.com/flamelink/media/vue-mastery-logo.png" />
22-
</div>
23-
</a>
24-
</div>
25-
26-
## What is Vue? {#what-is-vue}
27-
28-
Vue (pronounced /vjuː/, like **view**) is a JavaScript framework for building user interfaces. It builds on top of standard HTML, CSS, and JavaScript and provides a declarative, component-based programming model that helps you efficiently develop user interfaces of any complexity.
29-
30-
Here is a minimal example:
31-
32-
<div class="options-api">
33-
34-
```js
35-
import { createApp } from 'vue'
36-
37-
createApp({
38-
data() {
39-
return {
40-
count: 0
41-
}
42-
}
43-
}).mount('#app')
44-
```
45-
46-
</div>
47-
<div class="composition-api">
48-
49-
```js
50-
import { createApp, ref } from 'vue'
51-
52-
createApp({
53-
setup() {
54-
return {
55-
count: ref(0)
56-
}
57-
}
58-
}).mount('#app')
59-
```
60-
61-
</div>
62-
63-
```vue-html
64-
<div id="app">
65-
<button @click="count++">
66-
Count is: {{ count }}
67-
</button>
68-
</div>
69-
```
70-
71-
**Result**
72-
73-
<script setup>
74-
import { ref } from 'vue'
75-
const count = ref(0)
76-
</script>
77-
78-
<div class="demo">
79-
<button @click="count++">
80-
Count is: {{ count }}
81-
</button>
82-
</div>
83-
84-
The above example demonstrates the two core features of Vue:
85-
86-
- **Declarative Rendering**: Vue extends standard HTML with a template syntax that allows us to declaratively describe HTML output based on JavaScript state.
87-
88-
- **Reactivity**: Vue automatically tracks JavaScript state changes and efficiently updates the DOM when changes happen.
89-
90-
You may already have questions - don't worry. We will cover every little detail in the rest of the documentation. For now, please read along so you can have a high-level understanding of what Vue offers.
91-
92-
:::tip Prerequisites
93-
The rest of the documentation assumes basic familiarity with HTML, CSS, and JavaScript. If you are totally new to frontend development, it might not be the best idea to jump right into a framework as your first step - grasp the basics and then come back! You can check your knowledge level with these overviews for [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript), [HTML](https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML) and [CSS](https://developer.mozilla.org/en-US/docs/Learn/CSS/First_steps) if needed. Prior experience with other frameworks helps, but is not required.
94-
:::
95-
96-
## The Progressive Framework {#the-progressive-framework}
97-
98-
Vue is a framework and ecosystem that covers most of the common features needed in frontend development. But the web is extremely diverse - the things we build on the web may vary drastically in form and scale. With that in mind, Vue is designed to be flexible and incrementally adoptable. Depending on your use case, Vue can be used in different ways:
99-
100-
- Enhancing static HTML without a build step
101-
- Embedding as Web Components on any page
102-
- Single-Page Application (SPA)
103-
- Fullstack / Server-Side Rendering (SSR)
104-
- Jamstack / Static Site Generation (SSG)
105-
- Targeting desktop, mobile, WebGL, and even the terminal
106-
107-
If you find these concepts intimidating, don't worry! The tutorial and guide only require basic HTML and JavaScript knowledge, and you should be able to follow along without being an expert in any of these.
108-
109-
If you are an experienced developer interested in how to best integrate Vue into your stack, or you are curious about what these terms mean, we discuss them in more detail in [Ways of Using Vue](/guide/extras/ways-of-using-vue).
110-
111-
Despite the flexibility, the core knowledge about how Vue works is shared across all these use cases. Even if you are just a beginner now, the knowledge gained along the way will stay useful as you grow to tackle more ambitious goals in the future. If you are a veteran, you can pick the optimal way to leverage Vue based on the problems you are trying to solve, while retaining the same productivity. This is why we call Vue "The Progressive Framework": it's a framework that can grow with you and adapt to your needs.
112-
113-
## Single-File Components {#single-file-components}
114-
115-
In most build-tool-enabled Vue projects, we author Vue components using an HTML-like file format called **Single-File Component** (also known as `*.vue` files, abbreviated as **SFC**). A Vue SFC, as the name suggests, encapsulates the component's logic (JavaScript), template (HTML), and styles (CSS) in a single file. Here's the previous example, written in SFC format:
116-
117-
<div class="options-api">
118-
119-
```vue
120-
<script>
121-
export default {
122-
data() {
123-
return {
124-
count: 0
125-
}
126-
}
127-
}
128-
</script>
129-
130-
<template>
131-
<button @click="count++">Count is: {{ count }}</button>
132-
</template>
133-
134-
<style scoped>
135-
button {
136-
font-weight: bold;
137-
}
138-
</style>
139-
```
140-
141-
</div>
142-
<div class="composition-api">
143-
144-
```vue
145-
<script setup>
146-
import { ref } from 'vue'
147-
const count = ref(0)
148-
</script>
149-
150-
<template>
151-
<button @click="count++">Count is: {{ count }}</button>
152-
</template>
153-
154-
<style scoped>
155-
button {
156-
font-weight: bold;
157-
}
158-
</style>
159-
```
160-
161-
</div>
162-
163-
SFC is a defining feature of Vue and is the recommended way to author Vue components **if** your use case warrants a build setup. You can learn more about the [how and why of SFC](/guide/scaling-up/sfc) in its dedicated section - but for now, just know that Vue will handle all the build tools setup for you.
164-
165-
## API Styles {#api-styles}
166-
167-
Vue components can be authored in two different API styles: **Options API** and **Composition API**.
168-
169-
### Options API {#options-api}
170-
171-
With Options API, we define a component's logic using an object of options such as `data`, `methods`, and `mounted`. Properties defined by options are exposed on `this` inside functions, which points to the component instance:
172-
173-
```vue
174-
<script>
175-
export default {
176-
// Properties returned from data() become reactive state
177-
// and will be exposed on `this`.
178-
data() {
179-
return {
180-
count: 0
181-
}
182-
},
183-
184-
// Methods are functions that mutate state and trigger updates.
185-
// They can be bound as event handlers in templates.
186-
methods: {
187-
increment() {
188-
this.count++
189-
}
190-
},
191-
192-
// Lifecycle hooks are called at different stages
193-
// of a component's lifecycle.
194-
// This function will be called when the component is mounted.
195-
mounted() {
196-
console.log(`The initial count is ${this.count}.`)
197-
}
198-
}
199-
</script>
200-
201-
<template>
202-
<button @click="increment">Count is: {{ count }}</button>
203-
</template>
204-
```
205-
206-
[Try it in the Playground](https://play.vuejs.org/#eNptkMFqxCAQhl9lkB522ZL0HNKlpa/Qo4e1ZpLIGhUdl5bgu9es2eSyIMio833zO7NP56pbRNawNkivHJ25wV9nPUGHvYiaYOYGoK7Bo5CkbgiBBOFy2AkSh2N5APmeojePCkDaaKiBt1KnZUuv3Ky0PppMsyYAjYJgigu0oEGYDsirYUAP0WULhqVrQhptF5qHQhnpcUJD+wyQaSpUd/Xp9NysVY/yT2qE0dprIS/vsds5Mg9mNVbaDofL94jZpUgJXUKBCvAy76ZUXY53CTd5tfX2k7kgnJzOCXIF0P5EImvgQ2olr++cbRE4O3+t6JxvXj0ptXVpye1tvbFY+ge/NJZt)
207-
208-
### Composition API {#composition-api}
209-
210-
With Composition API, we define a component's logic using imported API functions. In SFCs, Composition API is typically used with [`<script setup>`](/api/sfc-script-setup). The `setup` attribute is a hint that makes Vue perform compile-time transforms that allow us to use Composition API with less boilerplate. For example, imports and top-level variables / functions declared in `<script setup>` are directly usable in the template.
211-
212-
Here is the same component, with the exact same template, but using Composition API and `<script setup>` instead:
213-
214-
```vue
215-
<script setup>
216-
import { ref, onMounted } from 'vue'
217-
218-
// reactive state
219-
const count = ref(0)
220-
221-
// functions that mutate state and trigger updates
222-
function increment() {
223-
count.value++
224-
}
225-
226-
// lifecycle hooks
227-
onMounted(() => {
228-
console.log(`The initial count is ${count.value}.`)
229-
})
230-
</script>
231-
232-
<template>
233-
<button @click="increment">Count is: {{ count }}</button>
234-
</template>
235-
```
236-
237-
[Try it in the Playground](https://play.vuejs.org/#eNpNkMFqwzAQRH9lMYU4pNg9Bye09NxbjzrEVda2iLwS0spQjP69a+yYHnRYad7MaOfiw/tqSliciybqYDxDRE7+qsiM3gWGGQJ2r+DoyyVivEOGLrgRDkIdFCmqa1G0ms2EELllVKQdRQa9AHBZ+PLtuEm7RCKVd+ChZRjTQqwctHQHDqbvMUDyd7mKip4AGNIBRyQujzArgtW/mlqb8HRSlLcEazrUv9oiDM49xGGvXgp5uT5his5iZV1f3r4HFHvDprVbaxPhZf4XkKub/CDLaep1T7IhGRhHb6WoTADNT2KWpu/aGv24qGKvrIrr5+Z7hnneQnJu6hURvKl3ryL/ARrVkuI=)
238-
239-
### Which to Choose? {#which-to-choose}
240-
241-
Both API styles are fully capable of covering common use cases. They are different interfaces powered by the exact same underlying system. In fact, the Options API is implemented on top of the Composition API! The fundamental concepts and knowledge about Vue are shared across the two styles.
242-
243-
The Options API is centered around the concept of a "component instance" (`this` as seen in the example), which typically aligns better with a class-based mental model for users coming from OOP language backgrounds. It is also more beginner-friendly by abstracting away the reactivity details and enforcing code organization via option groups.
244-
245-
The Composition API is centered around declaring reactive state variables directly in a function scope and composing state from multiple functions together to handle complexity. It is more free-form and requires an understanding of how reactivity works in Vue to be used effectively. In return, its flexibility enables more powerful patterns for organizing and reusing logic.
246-
247-
You can learn more about the comparison between the two styles and the potential benefits of Composition API in the [Composition API FAQ](/guide/extras/composition-api-faq).
248-
249-
If you are new to Vue, here's our general recommendation:
250-
251-
- For learning purposes, go with the style that looks easier to understand to you. Again, most of the core concepts are shared between the two styles. You can always pick up the other style later.
252-
253-
- For production use:
254-
255-
- Go with Options API if you are not using build tools, or plan to use Vue primarily in low-complexity scenarios, e.g. progressive enhancement.
256-
257-
- Go with Composition API + Single-File Components if you plan to build full applications with Vue.
258-
259-
You don't have to commit to only one style during the learning phase. The rest of the documentation will provide code samples in both styles where applicable, and you can toggle between them at any time using the **API Preference switches** at the top of the left sidebar.
260-
261-
## Still Got Questions? {#still-got-questions}
262-
263-
Check out our [FAQ](/about/faq).
264-
265-
## Pick Your Learning Path {#pick-your-learning-path}
266-
267-
Different developers have different learning styles. Feel free to pick a learning path that suits your preference - although we do recommend going over all of the content, if possible!
268-
269-
<div class="vt-box-container next-steps">
270-
<a class="vt-box" href="/tutorial/">
271-
<p class="next-steps-link">Try the Tutorial</p>
272-
<p class="next-steps-caption">For those who prefer learning things hands-on.</p>
273-
</a>
274-
<a class="vt-box" href="/guide/quick-start.html">
275-
<p class="next-steps-link">Read the Guide</p>
276-
<p class="next-steps-caption">The guide walks you through every aspect of the framework in full detail.</p>
277-
</a>
278-
<a class="vt-box" href="/examples/">
279-
<p class="next-steps-link">Check out the Examples</p>
280-
<p class="next-steps-caption">Explore examples of core features and common UI tasks.</p>
281-
</a>
282-
</div>

0 commit comments

Comments
 (0)