Skip to content

Commit 394408c

Browse files
committed
Merge branch 'develop' of http://github.com/Meituan-Dianping/mpvue into develop
2 parents 62e0fe5 + 17602b7 commit 394408c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/platforms/mp/runtime/lifecycle.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function getGlobalData (app, rootVueVM) {
4545
*/
4646
function normalizeProperties (vm) {
4747
const properties = vm.$options.properties || {}
48+
const vueProps = vm.$options.props || {}
4849
const res = {}
4950
let val
5051
for (const key in properties) {
@@ -62,6 +63,38 @@ function normalizeProperties (vm) {
6263
}
6364
}
6465
}
66+
67+
// 如果是以vue props写法定义属性
68+
// 纯数组定义属性 ['title', 'likes', 'isPublished', 'commentIds', 'author']
69+
if (Array.isArray(vueProps)) {
70+
for (const prop of vueProps) {
71+
// vue props定义的属性不覆盖properties原生形式定义的属性
72+
if (!res[prop]) {
73+
res[prop] = {
74+
type: null
75+
}
76+
}
77+
}
78+
} else {
79+
for (const key in vueProps) {
80+
val = isPlainObject(vueProps[key])
81+
? vueProps[key]
82+
: { type: vueProps[key] }
83+
res[key] = {
84+
// vue props的type可以是数组代表支持多种类型,但是小程序不支持,因此切换为任意类型
85+
type: Array.isArray(val.type) ? null : val.type,
86+
value: typeof val.default === 'function' ? val.default() : val.default,
87+
observer (newVal, oldVal) {
88+
vm[key] = newVal
89+
// 上面的赋值自带watch方法执行了,无需再调用watch方法
90+
// if (typeof watches[key] === 'function') {
91+
// watches[key].call(vm, newVal, oldVal)
92+
// }
93+
}
94+
}
95+
}
96+
}
97+
6598
return res
6699
}
67100

0 commit comments

Comments
 (0)