Skip to content

Commit 3f9075c

Browse files
authored
Merge pull request #645 from Meituan-Dianping/develop
Develop
2 parents 29cee1a + ddf6541 commit 3f9075c

File tree

13 files changed

+383
-67
lines changed

13 files changed

+383
-67
lines changed

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<a href="https://www.npmjs.com/package/mpvue"><img src="https://img.shields.io/npm/dm/mpvue.svg?style=flat" alt="npm"></a>
55
</p>
66

7-
# mpvue
7+
# mpvue
88
> Vue.js 小程序版, fork 自 [vuejs/vue@2.4.1](https://github.com/vuejs/vue),保留了 vue runtime 能力,添加了小程序平台的支持。
99
1010

@@ -60,8 +60,28 @@
6060
- [mpvue-simple](http://mpvue.com/mpvue/simple) 辅助 mpvue 快速开发 Page / Component 级小程序页面的工具
6161
- 其它
6262

63+
## 使用 mpvue 的项目
64+
<div>
65+
<img src="https://user-images.githubusercontent.com/13334618/38455900-d608df44-3ab0-11e8-94db-a5b7ac782612.jpg" width="100" />
66+
<img src="https://camo.githubusercontent.com/d0fe641cc98e6dcdff3b3e28f3f46ed47a3b5777/68747470733a2f2f7773312e73696e61696d672e636e2f6c617267652f36313134353733386c7931667139723334316a33356a323037363037363735392e6a7067" width="100" />
67+
<img src="https://user-images.githubusercontent.com/26051070/39106618-75ed54b4-46ef-11e8-834d-faf2629c218b.jpg" width="100" />
68+
<img src="https://user-images.githubusercontent.com/12172868/39176660-e973d0de-47df-11e8-88c2-fbd36b14caed.jpg" width="100" />
69+
<img src="https://user-images.githubusercontent.com/8087694/39505682-93727596-4e06-11e8-8978-6075d6b03742.jpg" width="100" />
70+
<img src="https://user-images.githubusercontent.com/16408246/40176958-ac78023a-5a0f-11e8-85bf-0ff56426f202.jpg" width="100" />
71+
<img src="https://user-images.githubusercontent.com/7871813/39956784-b3b978c0-5619-11e8-9bc4-658c8f2907e6.png" width="100" />
72+
<img src="https://user-images.githubusercontent.com/8219610/40181466-b8e1f204-5a1b-11e8-9c39-545226b354b6.jpg" width="100" />
73+
<img src="https://user-images.githubusercontent.com/8426097/40212791-72744312-5a84-11e8-819d-654057def4a2.jpg" width="100" />
74+
<img src="https://user-images.githubusercontent.com/22385741/40222981-fd28501e-5ab3-11e8-8558-79447270e118.png" width="100" />
75+
<img src="https://user-images.githubusercontent.com/28003460/40229157-017bcc24-5ac6-11e8-921a-f424a70724dd.jpg" width="100" />
76+
<img src="https://user-images.githubusercontent.com/20151096/40263981-a4072682-5b4d-11e8-95aa-292da6ee9228.png" width="100" />
77+
<img src="https://user-images.githubusercontent.com/652171/40602836-a064ab44-628c-11e8-962c-c5c75455c1c8.jpg" width="100" />
78+
<img src="https://camo.githubusercontent.com/735d3be145d2632dd010b5fe6e047bc1f5d1b56d/68747470733a2f2f692e6c6f6c692e6e65742f323031382f30362f30342f356231346536616634633537322e6a7067" width="100" />
79+
<img src="https://user-images.githubusercontent.com/5120505/41412484-ba85a04e-7012-11e8-9833-3ed4762073ea.png" width="100" />
80+
<img src="https://user-images.githubusercontent.com/22720942/40184432-da33291c-5a22-11e8-966c-c836d1dc8078.png" width="100" />
81+
</div>
82+
6383
[贡献方法](./.github/CONTRIBUTING.md)
6484

65-
[使用 mpvue 的项目征集](https://github.com/Meituan-Dianping/mpvue/issues/21)
85+
[更多项目征集](https://github.com/Meituan-Dianping/mpvue/issues/21)
6686

6787
[分享交流群](https://github.com/Meituan-Dianping/mpvue/issues/14)

packages/mpvue-template-compiler/build.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,11 @@ var LIFECYCLE_HOOKS = [
11091109
'onReachBottom',
11101110
'onShareAppMessage',
11111111
'onPageScroll',
1112-
'onTabItemTap'
1112+
'onTabItemTap',
1113+
'attached',
1114+
'ready',
1115+
'moved',
1116+
'detached'
11131117
];
11141118

11151119
/* */
@@ -4820,7 +4824,7 @@ function generate$2 (obj, options) {
48204824
var attrs = Object.keys(attrsMap).map(function (k) { return convertAttr(k, attrsMap[k]); }).join(' ');
48214825

48224826
var tags = ['progress', 'checkbox', 'switch', 'input', 'radio', 'slider', 'textarea'];
4823-
if (tags.indexOf(tag) > -1) {
4827+
if (tags.indexOf(tag) > -1 && !(children && children.length)) {
48244828
return ("<" + tag + (attrs ? ' ' + attrs : '') + " />" + (ifConditionsArr.join('')))
48254829
}
48264830
return ("<" + tag + (attrs ? ' ' + attrs : '') + ">" + (child || '') + "</" + tag + ">" + (ifConditionsArr.join('')))

packages/mpvue-template-compiler/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mpvue-template-compiler",
3-
"version": "1.0.12",
3+
"version": "1.0.13",
44
"description": "mpvue template compiler for Vue",
55
"main": "index.js",
66
"repository": {

packages/mpvue/index.js

Lines changed: 104 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,11 @@ var LIFECYCLE_HOOKS = [
322322
'onReachBottom',
323323
'onShareAppMessage',
324324
'onPageScroll',
325-
'onTabItemTap'
325+
'onTabItemTap',
326+
'attached',
327+
'ready',
328+
'moved',
329+
'detached'
326330
];
327331

328332
/* */
@@ -4144,7 +4148,7 @@ Object.defineProperty(Vue$3.prototype, '$ssrContext', {
41444148
});
41454149

41464150
Vue$3.version = '2.4.1';
4147-
Vue$3.mpvueVersion = '1.0.11';
4151+
Vue$3.mpvueVersion = '1.0.12';
41484152

41494153
/* globals renderer */
41504154

@@ -4974,30 +4978,106 @@ function getGlobalData (app, rootVueVM) {
49744978
}
49754979
}
49764980

4977-
/**
4978-
* 格式化 properties 属性,并给每个属性加上 observer 方法
4979-
*/
4981+
// 格式化 properties 属性,并给每个属性加上 observer 方法
4982+
4983+
// properties 的 一些类型 https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/component.html
4984+
// properties: {
4985+
// paramA: Number,
4986+
// myProperty: { // 属性名
4987+
// type: String, // 类型(必填),目前接受的类型包括:String, Number, Boolean, Object, Array, null(表示任意类型)
4988+
// value: '', // 属性初始值(可选),如果未指定则会根据类型选择一个
4989+
// observer: function(newVal, oldVal, changedPath) {
4990+
// // 属性被改变时执行的函数(可选),也可以写成在methods段中定义的方法名字符串, 如:'_propertyChange'
4991+
// // 通常 newVal 就是新设置的数据, oldVal 是旧数据
4992+
// }
4993+
// },
4994+
// }
4995+
4996+
// props 的一些类型 https://cn.vuejs.org/v2/guide/components-props.html#ad
4997+
// props: {
4998+
// // 基础的类型检查 (`null` 匹配任何类型)
4999+
// propA: Number,
5000+
// // 多个可能的类型
5001+
// propB: [String, Number],
5002+
// // 必填的字符串
5003+
// propC: {
5004+
// type: String,
5005+
// required: true
5006+
// },
5007+
// // 带有默认值的数字
5008+
// propD: {
5009+
// type: Number,
5010+
// default: 100
5011+
// },
5012+
// // 带有默认值的对象
5013+
// propE: {
5014+
// type: Object,
5015+
// // 对象或数组且一定会从一个工厂函数返回默认值
5016+
// default: function () {
5017+
// return { message: 'hello' }
5018+
// }
5019+
// },
5020+
// // 自定义验证函数
5021+
// propF: {
5022+
// validator: function (value) {
5023+
// // 这个值必须匹配下列字符串中的一个
5024+
// return ['success', 'warning', 'danger'].indexOf(value) !== -1
5025+
// }
5026+
// }
5027+
// }
5028+
5029+
// core/util/options
5030+
function normalizeProps$1 (props, res, vm) {
5031+
if (!props) { return }
5032+
var i, val, name;
5033+
if (Array.isArray(props)) {
5034+
i = props.length;
5035+
while (i--) {
5036+
val = props[i];
5037+
if (typeof val === 'string') {
5038+
name = camelize(val);
5039+
res[name] = { type: null };
5040+
} else {}
5041+
}
5042+
} else if (isPlainObject(props)) {
5043+
for (var key in props) {
5044+
val = props[key];
5045+
name = camelize(key);
5046+
res[name] = isPlainObject(val)
5047+
? val
5048+
: { type: val };
5049+
}
5050+
}
5051+
5052+
// fix vueProps to properties
5053+
for (var key$1 in res) {
5054+
if (res.hasOwnProperty(key$1)) {
5055+
var item = res[key$1];
5056+
if (item.default) {
5057+
item.value = item.default;
5058+
}
5059+
var oldObserver = item.observer;
5060+
item.observer = function (newVal, oldVal) {
5061+
vm[name] = newVal;
5062+
// 先修改值再触发原始的 observer,跟 watch 行为保持一致
5063+
if (typeof oldObserver === 'function') {
5064+
oldObserver.call(vm, newVal, oldVal);
5065+
}
5066+
};
5067+
}
5068+
}
5069+
5070+
return res
5071+
}
5072+
49805073
function normalizeProperties (vm) {
4981-
var properties = vm.$options.properties || {};
5074+
var properties = vm.$options.properties;
5075+
var vueProps = vm.$options.props;
49825076
var res = {};
4983-
var val;
4984-
var loop = function ( key ) {
4985-
val = isPlainObject(properties[key])
4986-
? properties[key]
4987-
: { type: properties[key] };
4988-
res[key] = {
4989-
type: val.type,
4990-
value: val.value,
4991-
observer: function observer (newVal, oldVal) {
4992-
vm[key] = newVal; // 先修改值再触发原始的 observer,跟 watch 行为保持一致
4993-
if (typeof val.observer === 'function') {
4994-
val.observer.call(vm, newVal, oldVal);
4995-
}
4996-
}
4997-
};
4998-
};
49995077

5000-
for (var key in properties) loop( key );
5078+
normalizeProps$1(properties, res, vm);
5079+
normalizeProps$1(vueProps, res, vm);
5080+
50015081
return res
50025082
}
50035083

@@ -5112,7 +5192,7 @@ function initMP (mpType, next) {
51125192
ready: function ready () {
51135193
mp.status = 'ready';
51145194

5115-
callHook$1(rootVueVM, 'onReady');
5195+
callHook$1(rootVueVM, 'ready');
51165196
next();
51175197

51185198
// 只有页面需要 setData
@@ -5491,13 +5571,6 @@ function handleProxyWithVue (e) {
54915571
return result
54925572
}
54935573
handles.forEach(function (h) { return h(event); });
5494-
} else {
5495-
// TODO, 在初始化时进行判断或直接使用 vue 本身的错误提示
5496-
var ref$1 = rootVueVM.$mp.page;
5497-
var route = ref$1.route;
5498-
console.group(new Date() + ' 事件警告');
5499-
console.warn(("Do not have handler in current page: " + route + ". Please make sure that handler has been defined in " + route + ", or not use handler with 'v-if'"));
5500-
console.groupEnd();
55015574
}
55025575
}
55035576

packages/mpvue/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mpvue",
3-
"version": "1.0.12",
3+
"version": "1.0.13",
44
"description": "Vue Runtime for mini program",
55
"main": "index.js",
66
"repository": {

src/platforms/mp/compiler/codegen/generate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default function generate (obj, options = {}) {
1919
const attrs = Object.keys(attrsMap).map(k => convertAttr(k, attrsMap[k])).join(' ')
2020

2121
const tags = ['progress', 'checkbox', 'switch', 'input', 'radio', 'slider', 'textarea']
22-
if (tags.indexOf(tag) > -1) {
22+
if (tags.indexOf(tag) > -1 && !(children && children.length)) {
2323
return `<${tag}${attrs ? ' ' + attrs : ''} />${ifConditionsArr.join('')}`
2424
}
2525
return `<${tag}${attrs ? ' ' + attrs : ''}>${child || ''}</${tag}>${ifConditionsArr.join('')}`

src/platforms/mp/join-code-in-build.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ exports.mpLifecycleHooks = `'onLaunch',
2323
'onReachBottom',
2424
'onShareAppMessage',
2525
'onPageScroll',
26-
'onTabItemTap'`
26+
'onTabItemTap',
27+
'attached',
28+
'ready',
29+
'moved',
30+
'detached'`

src/platforms/mp/runtime/events.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,5 @@ export function handleProxyWithVue (e) {
104104
return result
105105
}
106106
handles.forEach(h => h(event))
107-
} else {
108-
// TODO, 在初始化时进行判断或直接使用 vue 本身的错误提示
109-
const { route } = rootVueVM.$mp.page
110-
console.group(new Date() + ' 事件警告')
111-
console.warn(`Do not have handler in current page: ${route}. Please make sure that handler has been defined in ${route}, or not use handler with 'v-if'`)
112-
console.groupEnd()
113107
}
114108
}

0 commit comments

Comments
 (0)