Skip to content

Commit 9bf0a6a

Browse files
docs: replaced first example in Introduction (#343)
* chore: replaced first example in Introduction * fix: added button to stop interval
1 parent 1aa1792 commit 9bf0a6a

File tree

2 files changed

+62
-12
lines changed

2 files changed

+62
-12
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<template>
2+
<div class="demo">
3+
<p>Counter: {{ counter }}</p>
4+
<button @click="clearInterval">Stop timer</button>
5+
</div>
6+
</template>
7+
8+
<script>
9+
export default {
10+
data() {
11+
return {
12+
counter: 0,
13+
interval: null
14+
}
15+
},
16+
methods: {
17+
clearInterval() {
18+
clearInterval(this.interval)
19+
}
20+
},
21+
mounted() {
22+
this.interval = setInterval(() => {
23+
this.counter++
24+
}, 1000)
25+
}
26+
}
27+
</script>
28+
29+
<style lang="scss" scoped>
30+
.demo {
31+
font-family: sans-serif;
32+
border: 1px solid #eee;
33+
border-radius: 2px;
34+
padding: 20px 30px;
35+
margin-top: 1em;
36+
margin-bottom: 40px;
37+
user-select: none;
38+
overflow-x: auto;
39+
}
40+
</style>

src/guide/introduction.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,41 @@ The [Installation](installation.md) page provides more options of installing Vue
2929
At the core of Vue.js is a system that enables us to declaratively render data to the DOM using straightforward template syntax:
3030

3131
```html
32-
<div id="hello-vue">
33-
{{ message }}
32+
<div id="counter">
33+
Counter: {{ counter }}
3434
</div>
3535
```
3636

3737
```js
38-
const HelloVueApp = {
38+
const CounterApp = {
3939
data() {
4040
return {
41-
message: 'Hello Vue!'
41+
counter: 0
4242
}
4343
}
4444
}
4545

46-
Vue.createApp(HelloVueApp).mount('#hello-vue')
46+
Vue.createApp(CounterApp).mount('#counter')
4747
```
4848

49-
We have already created our very first Vue app! This looks pretty similar to rendering a string template, but Vue has done a lot of work under the hood. The data and the DOM are now linked, and everything is now **reactive**. How do we know? Change the `message` property in the code snippet below to a different value and the rendered example will update accordingly:
49+
We have already created our very first Vue app! This looks pretty similar to rendering a string template, but Vue has done a lot of work under the hood. The data and the DOM are now linked, and everything is now **reactive**. How do we know? Take a look at the example below where `counter` property increments every second and you will see how rendered DOM changes:
5050

51-
<p class="codepen" data-height="300" data-theme-id="39028" data-default-tab="js,result" data-user="Vue" data-slug-hash="KKpRVpx" data-editable="true" style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;" data-pen-title="Hello Vue">
52-
<span>See the Pen <a href="https://codepen.io/team/Vue/pen/KKpRVpx">
53-
Hello Vue</a> by Vue (<a href="https://codepen.io/Vue">@Vue</a>)
54-
on <a href="https://codepen.io">CodePen</a>.</span>
55-
</p>
56-
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
51+
```js{8-10}
52+
const CounterApp = {
53+
data() {
54+
return {
55+
counter: 0
56+
}
57+
},
58+
mounted() {
59+
setInterval(() => {
60+
this.counter++
61+
}, 1000)
62+
}
63+
}
64+
```
65+
66+
<FirstExample />
5767

5868
In addition to text interpolation, we can also bind element attributes like this:
5969

0 commit comments

Comments
 (0)