Skip to content

Commit b39634f

Browse files
committed
fix compat with vue 2.2
1 parent 3786c53 commit b39634f

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/data.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,22 @@ export function collectDataFromConstructor (vm: Vue, Component: VueClass) {
66
// override _init to prevent to init as Vue instance
77
Component.prototype._init = function (this: Vue) {
88
// proxy to actual vm
9-
Object.getOwnPropertyNames(vm).forEach(key => {
10-
Object.defineProperty(this, key, {
11-
get: () => vm[key],
12-
set: value => vm[key] = value
13-
})
9+
const keys = Object.getOwnPropertyNames(vm)
10+
// 2.2.0 compat (props are no longer exposed as self properties)
11+
if (vm.$options.props) {
12+
for (const key in vm.$options.props) {
13+
if (!vm.hasOwnProperty(key)) {
14+
keys.push(key)
15+
}
16+
}
17+
}
18+
keys.forEach(key => {
19+
if (key.charAt(0) !== '_') {
20+
Object.defineProperty(this, key, {
21+
get: () => vm[key],
22+
set: value => vm[key] = value
23+
})
24+
}
1425
})
1526
}
1627

0 commit comments

Comments
 (0)