forked from vuejs/vue-class-component
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.vue
62 lines (54 loc) · 1.1 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<template>
<div>
<input v-model="msg">
<p>prop: {{ propMessage }}</p>
<p>msg: {{ msg }}</p>
<p>helloMsg: {{ helloMsg }}</p>
<p>computed msg: {{ computedMsg }}</p>
<Hello ref="helloComponent" />
<World />
<button @click="greet">Greet</button>
</div>
</template>
<script lang="ts">
import Vue from 'vue'
import Component from '../lib/index'
import Hello from './Hello.vue'
import World from './World'
// We declare the props separately
// to make props types inferable.
const AppProps = Vue.extend({
props: {
propMessage: String
}
})
@Component({
components: {
Hello,
World
}
})
export default class App extends AppProps {
// inital data
msg: number = 123
// use prop values for initial data
helloMsg: string = 'Hello, ' + this.propMessage
// lifecycle hook
mounted () {
this.greet()
}
// computed
get computedMsg () {
return 'computed ' + this.msg
}
// method
greet () {
alert('greeting: ' + this.msg)
this.$refs.helloComponent.sayHello()
}
// dynamic component
$refs!: {
helloComponent: Hello
}
}
</script>