Skip to content

Commit bd8f389

Browse files
authored
Adjust TypeScript example (#45)
* bump vue * adjust TypeScript example
1 parent 7ad6a84 commit bd8f389

File tree

5 files changed

+33
-26
lines changed

5 files changed

+33
-26
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Note:
2020

2121
5. For all other options, pass them to the decorator function.
2222

23+
### Example
24+
25+
Following is the example written in Babel. If you are looking for TypeScript version, [it's in the example directory](example/example.ts).
26+
2327
``` js
2428
import Vue from 'vue'
2529
import Component from 'vue-class-component'

example/example.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
<title></title>
66
</head>
77
<body>
8-
<div id="el"></div>
8+
<div id="el">
9+
<app prop-message="World!"></app>
10+
</div>
911
<script src="build.js"></script>
1012
</body>
1113
</html>

example/example.ts

+19-23
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
1-
import * as Vue from 'vue'
1+
import Vue = require('vue')
22
import Component from '../lib/index'
33

44
@Component({
55
props: {
66
propMessage: String
7-
}
7+
},
8+
template: `
9+
<div>
10+
<input v-model="msg">
11+
<p>prop: {{propMessage}}</p>
12+
<p>msg: {{msg}}</p>
13+
<p>helloMsg: {{helloMsg}}</p>
14+
<p>computed msg: {{computedMsg}}</p>
15+
<button @click="greet">Greet</button>
16+
</div>
17+
`
818
})
919
class App extends Vue {
1020
propMessage: string
21+
22+
// inital data
1123
msg: number = 123
24+
25+
// use prop values for initial data
1226
helloMsg: string = 'Hello, ' + this.propMessage
1327

1428
// lifecycle hook
@@ -25,30 +39,12 @@ class App extends Vue {
2539
greet () {
2640
alert('greeting: ' + this.msg)
2741
}
28-
29-
render (h: Vue.CreateElement) {
30-
return (
31-
h('div', [
32-
h('input', {
33-
domProps: { value: this.msg },
34-
on: {
35-
input: (event: any) => {
36-
this.msg = event.target.value
37-
}
38-
}
39-
}),
40-
h('p', ['prop: ', this.propMessage]),
41-
h('p', ['msg: ', this.msg]),
42-
h('p', ['helloMsg: ', this.helloMsg]),
43-
h('p', ['computed msg: ', this.computedMsg]),
44-
h('button', { on: { click: this.greet }}, ['Greet'])
45-
])
46-
)
47-
}
4842
}
4943

5044
// mount
5145
new Vue({
5246
el: '#el',
53-
render: h => h(App, { props: { propMessage: 'World!' }})
47+
components: {
48+
App
49+
}
5450
})

example/webpack.config.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ module.exports = {
44
path: './example',
55
filename: 'build.js'
66
},
7+
resolve: {
8+
alias: {
9+
vue$: 'vue/dist/vue.common.js'
10+
}
11+
},
712
module: {
8-
loaders: [
13+
rules: [
914
{
1015
test: /\.ts$/,
1116
exclude: /node_modules|vue\/src/,

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"rimraf": "^2.5.4",
4848
"ts-loader": "^0.9.5",
4949
"typescript": "^2.0.6",
50-
"vue": "^2.0.3",
50+
"vue": "^2.1.6",
5151
"webpack": "^2.1.0-beta.27"
5252
}
5353
}

0 commit comments

Comments
 (0)