diff --git a/packages/uni-app-plus/dist/index.js b/packages/uni-app-plus/dist/index.js index 27ecea6103610673ab851778d41ef492b33e2353..9b1a0b12e2cb2e94d583af6ac51c2eef6bc3215d 100644 --- a/packages/uni-app-plus/dist/index.js +++ b/packages/uni-app-plus/dist/index.js @@ -393,7 +393,15 @@ function getBehaviors (vueExtends, vueMixins) { return behaviors } -function getProperties (props, isBehavior = false) { +function parsePropType (key, type, file) { + // [String]=>String + if (Array.isArray(type) && type.length === 1) { + return type[0] + } + return type +} + +function getProperties (props, isBehavior = false, file = '') { const properties = {}; if (!isBehavior) { properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots @@ -425,14 +433,18 @@ function getProperties (props, isBehavior = false) { if (isFn(value)) { value = value(); } + + opts.type = parsePropType(key, opts.type, file); + properties[key] = { type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null, value, observer: createObserver(key) }; } else { // content:String + const type = parsePropType(key, opts, file); properties[key] = { - type: PROP_TYPES.indexOf(opts) !== -1 ? opts : null, + type: PROP_TYPES.indexOf(type) !== -1 ? type : null, observer: createObserver(key) }; } @@ -875,7 +887,7 @@ function initVm$2 (VueComponent) { function createComponent (vueOptions) { vueOptions = vueOptions.default || vueOptions; - const properties = getProperties(vueOptions.props); + const properties = getProperties(vueOptions.props, false, vueOptions.__file); const behaviors = getBehaviors(vueOptions['extends'], vueOptions['mixins']); diff --git a/packages/uni-app-plus/package.json b/packages/uni-app-plus/package.json index 4466e963db03a2cf6b8922aa710d27c1b107f55d..edcb3831abbd3ddb6c7eaf89684a90aab97d4594 100644 --- a/packages/uni-app-plus/package.json +++ b/packages/uni-app-plus/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-app-plus", - "version": "0.0.223", + "version": "0.0.224", "description": "uni-app app-plus", "main": "dist/index.js", "scripts": { diff --git a/packages/uni-mp-baidu/dist/index.js b/packages/uni-mp-baidu/dist/index.js index 356b036ae2e994a470b0dacadc337470cd9c5fa6..6d9cf553a54d7b34815b3c1f9130594325f89177 100644 --- a/packages/uni-mp-baidu/dist/index.js +++ b/packages/uni-mp-baidu/dist/index.js @@ -528,7 +528,38 @@ function getBehaviors (vueExtends, vueMixins) { return behaviors } -function getProperties (props, isBehavior = false) { +function parsePropType (key, type, file) { + // [String]=>String + if (Array.isArray(type) && type.length === 1) { + return type[0] + } + { + if ( + Array.isArray(type) && + type.length === 2 && + type.indexOf(String) !== -1 + ) { // [String,Boolean]=>Boolean + if (type.indexOf(Boolean) !== -1) { + if (file) { + console.warn( + `props.${key}.type should use Boolean instead of [String,Boolean] . at ${file}` + ); + } + return Boolean + } else if (type.indexOf(Number) !== -1) { + if (file) { + console.warn( + `props.${key}.type should use String or Number instead of [String,Number]. at ${file}` + ); + } + return String + } + } + } + return type +} + +function getProperties (props, isBehavior = false, file = '') { const properties = {}; if (!isBehavior) { properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots @@ -560,14 +591,18 @@ function getProperties (props, isBehavior = false) { if (isFn(value)) { value = value(); } + + opts.type = parsePropType(key, opts.type, file); + properties[key] = { type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null, value, observer: createObserver(key) }; } else { // content:String + const type = parsePropType(key, opts, file); properties[key] = { - type: PROP_TYPES.indexOf(opts) !== -1 ? opts : null, + type: PROP_TYPES.indexOf(type) !== -1 ? type : null, observer: createObserver(key) }; } @@ -1042,7 +1077,7 @@ function initVm$2 (VueComponent) { function createComponent (vueOptions) { vueOptions = vueOptions.default || vueOptions; - const properties = getProperties(vueOptions.props); + const properties = getProperties(vueOptions.props, false, vueOptions.__file); const behaviors = getBehaviors(vueOptions['extends'], vueOptions['mixins']); diff --git a/packages/uni-mp-baidu/package.json b/packages/uni-mp-baidu/package.json index 506159b0eae08cc88d2a525c713417f905eaaa71..83b86e5d091263e83bc3598cc99ec91845876ca0 100644 --- a/packages/uni-mp-baidu/package.json +++ b/packages/uni-mp-baidu/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-baidu", - "version": "0.0.818", + "version": "0.0.820", "description": "uni-app mp-baidu", "main": "dist/index.js", "scripts": { diff --git a/packages/uni-mp-toutiao/dist/index.js b/packages/uni-mp-toutiao/dist/index.js index 655b83ddbfdfe2b452038582055d094424617bdd..4f4f9b1c05f95b88abb8b7805ad7eae5e5a308ae 100644 --- a/packages/uni-mp-toutiao/dist/index.js +++ b/packages/uni-mp-toutiao/dist/index.js @@ -573,7 +573,15 @@ function getBehaviors (vueExtends, vueMixins) { return behaviors } -function getProperties (props, isBehavior = false) { +function parsePropType (key, type, file) { + // [String]=>String + if (Array.isArray(type) && type.length === 1) { + return type[0] + } + return type +} + +function getProperties (props, isBehavior = false, file = '') { const properties = {}; if (!isBehavior) { properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots @@ -605,14 +613,18 @@ function getProperties (props, isBehavior = false) { if (isFn(value)) { value = value(); } + + opts.type = parsePropType(key, opts.type, file); + properties[key] = { type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null, value, observer: createObserver(key) }; } else { // content:String + const type = parsePropType(key, opts, file); properties[key] = { - type: PROP_TYPES.indexOf(opts) !== -1 ? opts : null, + type: PROP_TYPES.indexOf(type) !== -1 ? type : null, observer: createObserver(key) }; } @@ -1066,7 +1078,7 @@ function initVm$2 (VueComponent) { function createComponent (vueOptions) { vueOptions = vueOptions.default || vueOptions; - const properties = getProperties(vueOptions.props); + const properties = getProperties(vueOptions.props, false, vueOptions.__file); const behaviors = getBehaviors(vueOptions['extends'], vueOptions['mixins']); diff --git a/packages/uni-mp-toutiao/package.json b/packages/uni-mp-toutiao/package.json index a01bb1a01fa8b6b7f63ef3a6b4b108be69129a66..3178fd0be92486722b1bd615324eb5897ffc6e69 100644 --- a/packages/uni-mp-toutiao/package.json +++ b/packages/uni-mp-toutiao/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-toutiao", - "version": "0.0.318", + "version": "0.0.319", "description": "uni-app mp-toutiao", "main": "dist/index.js", "scripts": { diff --git a/packages/uni-mp-weixin/dist/index.js b/packages/uni-mp-weixin/dist/index.js index e688db42947164ec85d0891b717f34d38fddf657..ffb45f28fc11e64f5ff3ff759f0b66d310ac04a8 100644 --- a/packages/uni-mp-weixin/dist/index.js +++ b/packages/uni-mp-weixin/dist/index.js @@ -420,7 +420,15 @@ function getBehaviors (vueExtends, vueMixins) { return behaviors } -function getProperties (props, isBehavior = false) { +function parsePropType (key, type, file) { + // [String]=>String + if (Array.isArray(type) && type.length === 1) { + return type[0] + } + return type +} + +function getProperties (props, isBehavior = false, file = '') { const properties = {}; if (!isBehavior) { properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots @@ -452,14 +460,18 @@ function getProperties (props, isBehavior = false) { if (isFn(value)) { value = value(); } + + opts.type = parsePropType(key, opts.type, file); + properties[key] = { type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null, value, observer: createObserver(key) }; } else { // content:String + const type = parsePropType(key, opts, file); properties[key] = { - type: PROP_TYPES.indexOf(opts) !== -1 ? opts : null, + type: PROP_TYPES.indexOf(type) !== -1 ? type : null, observer: createObserver(key) }; } @@ -895,7 +907,7 @@ function initVm$2 (VueComponent) { function createComponent (vueOptions) { vueOptions = vueOptions.default || vueOptions; - const properties = getProperties(vueOptions.props); + const properties = getProperties(vueOptions.props, false, vueOptions.__file); const behaviors = getBehaviors(vueOptions['extends'], vueOptions['mixins']); diff --git a/packages/uni-mp-weixin/package.json b/packages/uni-mp-weixin/package.json index 8f96c5ab667f425cbb3fb25e68af07578d3a5508..e1a5b1d7fed1d5a84acedac67e7dc18594d835cb 100644 --- a/packages/uni-mp-weixin/package.json +++ b/packages/uni-mp-weixin/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-weixin", - "version": "0.0.942", + "version": "0.0.943", "description": "uni-app mp-weixin", "main": "dist/index.js", "scripts": { diff --git a/src/core/runtime/wrapper/create-component.js b/src/core/runtime/wrapper/create-component.js index fb65f668dd0697b8812e5dc2c75a4138a2099608..d492e0169660c497ab0021bc6401fe66b764f52d 100644 --- a/src/core/runtime/wrapper/create-component.js +++ b/src/core/runtime/wrapper/create-component.js @@ -43,7 +43,7 @@ function initVm (VueComponent) { export function createComponent (vueOptions) { vueOptions = vueOptions.default || vueOptions - const properties = getProperties(vueOptions.props) + const properties = getProperties(vueOptions.props, false, vueOptions.__file) const behaviors = getBehaviors(vueOptions['extends'], vueOptions['mixins']) diff --git a/src/core/runtime/wrapper/util.js b/src/core/runtime/wrapper/util.js index 937f86a6ae9cae183f8adf13d544476996fe10c2..6d3f25c4d13f51676a8d04bd7fccfb1da4521645 100644 --- a/src/core/runtime/wrapper/util.js +++ b/src/core/runtime/wrapper/util.js @@ -89,7 +89,38 @@ export function getBehaviors (vueExtends, vueMixins) { return behaviors } -export function getProperties (props, isBehavior = false) { +function parsePropType (key, type, file) { + // [String]=>String + if (Array.isArray(type) && type.length === 1) { + return type[0] + } + if (__PLATFORM__ === 'mp-baidu') { + if ( + Array.isArray(type) && + type.length === 2 && + type.indexOf(String) !== -1 + ) { // [String,Boolean]=>Boolean + if (type.indexOf(Boolean) !== -1) { + if (file) { + console.warn( + `props.${key}.type should use Boolean instead of [String,Boolean] . at ${file}` + ) + } + return Boolean + } else if (type.indexOf(Number) !== -1) { + if (file) { + console.warn( + `props.${key}.type should use String or Number instead of [String,Number]. at ${file}` + ) + } + return String + } + } + } + return type +} + +export function getProperties (props, isBehavior = false, file = '') { const properties = {} if (!isBehavior) { properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots @@ -121,14 +152,18 @@ export function getProperties (props, isBehavior = false) { if (isFn(value)) { value = value() } + + opts.type = parsePropType(key, opts.type, file) + properties[key] = { type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null, value, observer: createObserver(key) } } else { // content:String + const type = parsePropType(key, opts, file) properties[key] = { - type: PROP_TYPES.indexOf(opts) !== -1 ? opts : null, + type: PROP_TYPES.indexOf(type) !== -1 ? type : null, observer: createObserver(key) } }