Skip to content

Commit 30530b8

Browse files
bartlomiejuyyx990803
authored andcommitted
change enumeration method of component's computed props (#274)
1 parent f8310f4 commit 30530b8

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

shells/dev/target/Other.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,19 @@
66
</template>
77

88
<script>
9+
// this computed property should be visible
10+
// even if component has no 'computed' defined
11+
const computedPropMixin = {
12+
computed: {
13+
computedPropFromMixin() {
14+
return null
15+
}
16+
}
17+
}
18+
919
export default {
1020
props: ['id'],
21+
mixins: [ computedPropMixin ],
1122
data () {
1223
let a = { c: function () {} }
1324
a.a = a

src/backend/index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,23 +429,33 @@ function processState (instance) {
429429
*/
430430

431431
function processComputed (instance) {
432-
return Object.keys(instance.$options.computed || {}).map(key => {
432+
const computed = []
433+
// use for...in here because if 'computed' is not defined
434+
// on component, computed properties will be placed in prototype
435+
// and Object.keys does not include
436+
// properties from object's prototype
437+
for (const key in (instance.$options.computed || {})) {
433438
// use try ... catch here because some computed properties may
434439
// throw error during its evaluation
440+
let computedProp = null
435441
try {
436-
return {
442+
computedProp = {
437443
type: 'computed',
438444
key,
439445
value: instance[key]
440446
}
441447
} catch (e) {
442-
return {
448+
computedProp = {
443449
type: 'computed',
444450
key,
445451
value: '(error during evaluation)'
446452
}
447453
}
448-
})
454+
455+
computed.push(computedProp)
456+
}
457+
458+
return computed
449459
}
450460

451461
/**

0 commit comments

Comments
 (0)