Skip to content

Commit cafb944

Browse files
ktsnyyx990803
authored andcommitted
Update for Vue 2.0 (#20)
* update internal hook names for Vue 2.0 * update example for 2.0 * update readme
1 parent 98f4079 commit cafb944

File tree

5 files changed

+35
-24
lines changed

5 files changed

+35
-24
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Note:
1212

1313
2. Computed properties can be declared as class property accessors.
1414

15-
3. `data`, `el` and all Vue lifecycle hooks can be directly declared as class member methods as well, but you cannot invoke them on the instance itself. When declaring custom methods, you should avoid these reserved names.
15+
3. `data`, `render` and all Vue lifecycle hooks can be directly declared as class member methods as well, but you cannot invoke them on the instance itself. When declaring custom methods, you should avoid these reserved names.
1616

1717
4. For all other options, pass them to the decorator function.
1818

@@ -42,7 +42,7 @@ class App {
4242
}
4343

4444
// lifecycle hook
45-
ready () {
45+
mounted () {
4646
this.greet()
4747
}
4848

example/example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<title></title>
66
</head>
77
<body>
8-
<div id="el" prop-message="Hello!"></div>
8+
<div id="el"></div>
99
<script src="build.js"></script>
1010
</body>
1111
</html>

example/example.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,7 @@ import Component from '../'
33
@Component({
44
props: {
55
propMessage: String
6-
},
7-
template: `
8-
<div>
9-
<input v-model="msg">
10-
<p>prop: {{propMessage}}</p>
11-
<p>msg: {{msg}}</p>
12-
<p>computed msg: {{computedMsg}}</p>
13-
<button @click="greet">Greet</button>
14-
</div>
15-
`
6+
}
167
})
178
class App {
189
// return initial data
@@ -23,7 +14,7 @@ class App {
2314
}
2415

2516
// lifecycle hook
26-
ready () {
17+
mounted () {
2718
this.greet()
2819
}
2920

@@ -36,9 +27,29 @@ class App {
3627
greet () {
3728
alert('greeting: ' + this.msg)
3829
}
30+
31+
render (h) {
32+
return (
33+
h('div', [
34+
h('input', {
35+
domProps: { value: this.msg },
36+
on: {
37+
input: (event) => {
38+
this.msg = event.target.value
39+
}
40+
}
41+
}),
42+
h('p', ['prop: ', this.propMessage]),
43+
h('p', ['msg: ', this.msg]),
44+
h('p', ['computed msg: ', this.computedMsg]),
45+
h('button', { on: { click: this.greet }}, ['Greet'])
46+
])
47+
)
48+
}
3949
}
4050

4151
// mount
4252
new App({
43-
el: '#el'
53+
el: '#el',
54+
render: h => h(App, { props: { propMessage: 'Hello!' }})
4455
})

index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ var Vue = require('vue')
66

77
var internalHooks = [
88
'data',
9-
'el',
10-
'init',
9+
'beforeCreate',
1110
'created',
12-
'ready',
13-
'beforeCompile',
14-
'compiled',
11+
'beforeMount',
12+
'mounted',
1513
'beforeDestroy',
1614
'destroyed',
17-
'attached',
18-
'detached',
19-
'activate'
15+
'beforeUpdate',
16+
'updated',
17+
'activated',
18+
'deactivated',
19+
'render'
2020
]
2121

2222
function componentFactory (Component, options) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"chai": "^3.5.0",
3737
"mocha": "^2.4.5",
3838
"node-libs-browser": "^1.0.0",
39-
"vue": "^1.0.16",
39+
"vue": "^2.0.0-rc.4",
4040
"webpack": "^1.12.12"
4141
}
4242
}

0 commit comments

Comments
 (0)