8000 update basic example · vuejs/rfcs@112c6ed · GitHub
[go: up one dir, main page]

Skip to content

Commit 112c6ed

Browse files
committed
update basic example
1 parent 05f4912 commit 112c6ed

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

active-rfcs/0000-class-api.md

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ Introduce built-in support for authoring components as native ES2015 classes.
99

1010
# Basic example
1111

12-
``` js
13-
import Vue from 'vue'
12+
## In Browser
1413

15-
export default class App extends Vue {
14+
``` js
15+
class App extends Vue {
1616
// options declared via static properties (stage 3)
1717
// more details below
1818
static template = `
19-
<div>{{ count }}</div>
19+
<div @click="increment">
20+
{{ count }} {{ plusOne }}
21+
</div>
2022
`
2123

2224
// reactive data declared via class fields (stage 3)
@@ -40,6 +42,44 @@ export default class App extends Vue {
4042
}
4143
```
4244

45+
The component will be mounted using a new global API instead of `new Vue()` - this will be discussed in a separate RFC.
46+
47+
## In Single File Components
48+
49+
``` html
50+
<template>
51+
<div @click="increment">
52+
{{ count }} {{ plusOne }}
53+
<Foo />
54+
</div>
55+
</template>
56+
57+
<script>
58+
import Vue from 'vue'
59+
import Foo from './Foo.vue'
60+
61+
export default class App extends Vue {
62+
static components = {
63+
Foo
64+
}
65+
66+
count = 0
67+
68+
created() {
69+
console.log(this.count)
70+
}
71+
72+
get plusOne() {
73+
return this.count + 1
74+
}
75+
76+
increment() {
77+
this.count++
78+
}
79+
}
80+
</script>
81+
```
82+
4383
# Motivation
4484

4585
Vue's current object-based component API has created some challenges when it comes to type inference. As a result, most users opting into using Vue with TypeScript end up using [vue-class-component](https://github.com/vuejs/vue-class-component). This approach works, but with some drawbacks:

0 commit comments

Comments
 (0)
0