diff --git a/packages/uni-mp-alipay/__tests__/vSlot.spec.ts b/packages/uni-mp-alipay/__tests__/vSlot.spec.ts
index fa3c518b4984d8c00c4bfb5cba0942df8b6b410c..3702c74c68458a170996d1f23f97c86705c4867c 100644
--- a/packages/uni-mp-alipay/__tests__/vSlot.spec.ts
+++ b/packages/uni-mp-alipay/__tests__/vSlot.spec.ts
@@ -4,14 +4,14 @@ describe('mp-alipay: transform v-slot', () => {
test('default slot', () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`test`,
- `test`,
+ `test`,
`(_ctx, _cache) => {
return {}
}`
@@ -20,14 +20,14 @@ describe('mp-alipay: transform v-slot', () => {
test('named slots', () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`{{error.message}}`,
- `{{v0.b}}`,
+ `{{v0.b}}`,
`(_ctx, _cache) => {
return { a: _w(({ data, loading, error, options }, s0, i0) => { return _e({ a: error }, error ? { b: _t(error.message) } : {}, { c: i0, d: s0 }); }, { name: 'd', path: 'a', vueId: '2a9ec0b0-0' }) }
}`
diff --git a/packages/uni-mp-baidu/__tests__/vSlot.spec.ts b/packages/uni-mp-baidu/__tests__/vSlot.spec.ts
index c20001fa64d14b3367472c9237ecf995d55bb946..66d69e96250a790039af315339cfe3d3822ff030 100644
--- a/packages/uni-mp-baidu/__tests__/vSlot.spec.ts
+++ b/packages/uni-mp-baidu/__tests__/vSlot.spec.ts
@@ -4,14 +4,14 @@ describe('compiler: transform v-slot', () => {
test('default slot', () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`test`,
- `test`,
+ `test`,
`(_ctx, _cache) => {
return {}
}`
@@ -20,14 +20,14 @@ describe('compiler: transform v-slot', () => {
test('named slots', () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`{{error.message}}`,
- `{{v0.c}}`,
+ `{{v0.c}}`,
`(_ctx, _cache) => {
return { a: _w(({ data, loading, error, options }, s0, i0) => { return _e({ a: i0, b: error }, error ? { c: _t(error.message) } : {}); }, { name: 'd', path: 'a', vueId: '2a9ec0b0-0' }) }
}`
@@ -37,7 +37,7 @@ describe('compiler: transform v-slot', () => {
test('scoped slots', () => {
assert(
`{{ slotProps.item }}`,
- `{{slotProps.b}}`,
+ `{{slotProps.b}}`,
`(_ctx, _cache) => {
return { a: _w((slotProps, s0, i0) => { return { a: i0, b: _t(slotProps.item) }; }, { name: 'd', path: 'a', vueId: '2a9ec0b0-0' }) }
}`
@@ -47,7 +47,7 @@ describe('compiler: transform v-slot', () => {
test('scoped slots + scoped slots', () => {
assert(
`{{ slotProps.item }}{{ slotProps1.item }}`,
- `{{slotProps.c}}{{slotProps1.b}}`,
+ `{{slotProps.c}}{{slotProps1.b}}`,
`(_ctx, _cache) => {
return { a: _w((slotProps, s0, i0) => { return { a: i0, b: _w((slotProps1, s1, i1) => { return { a: i1, b: _t(slotProps1.item) }; }, { name: 'd', path: 'a[' + i0 + '].' + 'b', vueId: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0' }), c: _t(slotProps.item), d: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0' }; }, { name: 'd', path: 'a', vueId: '2a9ec0b0-0' }) }
}`
@@ -57,7 +57,7 @@ describe('compiler: transform v-slot', () => {
test('v-if + scoped slots', () => {
assert(
`{{ slotProps.item }}`,
- `{{slotProps.b}}`,
+ `{{slotProps.b}}`,
`(_ctx, _cache) => {
return _e({ a: _ctx.ok }, _ctx.ok ? { b: _w((slotProps, s0, i0) => { return { a: i0, b: _t(slotProps.item) }; }, { name: 'd', path: 'b', vueId: '2a9ec0b0-0' }) } : {})
}`
@@ -67,7 +67,7 @@ describe('compiler: transform v-slot', () => {
test('v-for + scoped slots', () => {
assert(
`{{ slotProps.item }}`,
- `{{slotProps.b}}`,
+ `{{slotProps.b}}`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _w((slotProps, s1, i1) => { return { a: i1, b: _t(slotProps.item) }; }, { name: 'd', path: 'a[' + i0 + '].' + 'a', vueId: '2a9ec0b0-0' + '-' + i0 }), b: '2a9ec0b0-0' + '-' + i0 }; }) }
}`
@@ -77,7 +77,7 @@ describe('compiler: transform v-slot', () => {
test('v-for + v-for + scoped slots', () => {
assert(
`{{ slotProps.item }}`,
- `{{slotProps.b}}`,
+ `{{slotProps.b}}`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _f(item.list, (item1, k1, i1) => { return { a: _w((slotProps, s2, i2) => { return { a: i2, b: _t(slotProps.item) }; }, { name: 'd', path: 'a[' + i0 + '].' + ('a[' + i1 + '].') + 'a', vueId: '2a9ec0b0-0' + '-' + i0 + '-' + i1 }), b: '2a9ec0b0-0' + '-' + i0 + '-' + i1, c: _p({ item: item1 }) }; }) }; }) }
}`
diff --git a/packages/uni-mp-baidu/dist/uni.mp.esm.js b/packages/uni-mp-baidu/dist/uni.mp.esm.js
index b09feb957a19a67a1e83f6157d5297859aad30a0..b41141be905a8122879c9d4b47d5545e514ce946 100644
--- a/packages/uni-mp-baidu/dist/uni.mp.esm.js
+++ b/packages/uni-mp-baidu/dist/uni.mp.esm.js
@@ -635,6 +635,29 @@ function initProps(mpComponentOptions) {
}
extend(mpComponentOptions.properties, initDefaultProps());
}
+const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
+function parsePropType(type, defaultValue) {
+ // [String]=>String
+ if (isArray(type) && type.length === 1) {
+ return type[0];
+ }
+ {
+ if (
+ // [String,Boolean]=>Boolean
+ defaultValue === false &&
+ isArray(type) &&
+ type.length === 2 &&
+ type.indexOf(String) !== -1 &&
+ type.indexOf(Boolean) !== -1) {
+ return Boolean;
+ }
+ }
+ return type;
+}
+function normalizePropType(type, defaultValue) {
+ const res = parsePropType(type, defaultValue);
+ return PROP_TYPES.indexOf(res) !== -1 ? res : null;
+}
/**
* 初始化页面 props,方便接收页面参数,类型均为String,默认值均为''
* @param param
@@ -651,10 +674,26 @@ function initPageProps({ properties }, rawProps) {
}
else if (isPlainObject(rawProps)) {
Object.keys(rawProps).forEach((key) => {
- properties[key] = {
- type: String,
- value: '',
- };
+ const opts = rawProps[key];
+ if (isPlainObject(opts)) {
+ // title:{type:String,default:''}
+ let value = opts.default;
+ if (isFunction(value)) {
+ value = value();
+ }
+ const type = opts.type;
+ opts.type = normalizePropType(type, value);
+ properties[key] = {
+ type: opts.type,
+ value,
+ };
+ }
+ else {
+ // content:String
+ properties[key] = {
+ type: normalizePropType(opts, null),
+ };
+ }
});
}
}
diff --git a/packages/uni-mp-compiler/__tests__/component.spec.ts b/packages/uni-mp-compiler/__tests__/component.spec.ts
index 98f8fb2752c084869252fd5bf8d0aec47de033f4..5e981289dc0f8f9ac68785c3f2d68cb60f326a12 100644
--- a/packages/uni-mp-compiler/__tests__/component.spec.ts
+++ b/packages/uni-mp-compiler/__tests__/component.spec.ts
@@ -10,7 +10,7 @@ describe('compiler: transform component', () => {
test('component + component', () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return {}
}`,
@@ -22,7 +22,7 @@ describe('compiler: transform component', () => {
test('component + component + component', () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return {}
}`,
@@ -56,7 +56,7 @@ describe('compiler: transform component', () => {
test('component + component with v-for', () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0' }; }) }
}`,
@@ -68,7 +68,7 @@ describe('compiler: transform component', () => {
test('component with v-for + component', () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-1' + '-' + i0 + ',' + ('2a9ec0b0-0' + '-' + i0), b: '2a9ec0b0-0' + '-' + i0 }; }) }
}`,
@@ -80,7 +80,7 @@ describe('compiler: transform component', () => {
test('component with v-for + component with v-for', () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _f(item.items, (item1, k1, i1) => { return { a: '2a9ec0b0-1' + '-' + i0 + '-' + i1 + ',' + ('2a9ec0b0-0' + '-' + i0) }; }), b: '2a9ec0b0-0' + '-' + i0 }; }) }
}`,
diff --git a/packages/uni-mp-compiler/__tests__/slot.spec.ts b/packages/uni-mp-compiler/__tests__/slot.spec.ts
index c2ccc52c6cfdf8f55801c5c4ab0401845a4024a0..76147a7be7571ec57f1c42de82a942153a76b63e 100644
--- a/packages/uni-mp-compiler/__tests__/slot.spec.ts
+++ b/packages/uni-mp-compiler/__tests__/slot.spec.ts
@@ -4,14 +4,14 @@ describe('compiler: transform slot', () => {
test('basic', () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return {}
}`
)
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return {}
}`
@@ -29,7 +29,7 @@ describe('compiler: transform slot', () => {
test('fallback content', () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return {}
}`
@@ -56,7 +56,7 @@ describe('compiler: transform slot', () => {
test('slot with component', () => {
assert(
`fallback`,
- `fallback`,
+ `fallback`,
`(_ctx, _cache) => {
return {}
}`
diff --git a/packages/uni-mp-compiler/__tests__/vFor.spec.ts b/packages/uni-mp-compiler/__tests__/vFor.spec.ts
index dfeba59e09149138786a8416b6b25dae2df90472..0d21865c12fdb135bf1ec4d937e001b91e4ab94f 100644
--- a/packages/uni-mp-compiler/__tests__/vFor.spec.ts
+++ b/packages/uni-mp-compiler/__tests__/vFor.spec.ts
@@ -158,7 +158,7 @@ describe(`compiler: v-for`, () => {
test(`template v-for w/ `, () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return {}; }) }
}`
@@ -177,7 +177,7 @@ describe(`compiler: v-for`, () => {
test(`v-for on `, () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return {}; }) }
}`
diff --git a/packages/uni-mp-compiler/__tests__/vIf.spec.ts b/packages/uni-mp-compiler/__tests__/vIf.spec.ts
index bdfc15b44860e10af90ec1b5815a2b7d6c084c5a..35a2bbf4dfcfbf03b733c469e1b788bbbe3b9a90 100644
--- a/packages/uni-mp-compiler/__tests__/vIf.spec.ts
+++ b/packages/uni-mp-compiler/__tests__/vIf.spec.ts
@@ -50,7 +50,7 @@ describe(`compiler: v-if`, () => {
test(`template v-if w/ single child`, () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return _e({ a: _ctx.ok }, _ctx.ok ? {} : {})
}`
@@ -59,7 +59,7 @@ describe(`compiler: v-if`, () => {
test(`v-if on `, () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return _e({ a: _ctx.ok }, _ctx.ok ? {} : {})
}`
diff --git a/packages/uni-mp-compiler/__tests__/vSlot.spec.ts b/packages/uni-mp-compiler/__tests__/vSlot.spec.ts
index de3b44d5baf0053a8129544d4807c7d34f58627a..6abbdaed310ee7e46a8cb9dde471b3ce7896fe3d 100644
--- a/packages/uni-mp-compiler/__tests__/vSlot.spec.ts
+++ b/packages/uni-mp-compiler/__tests__/vSlot.spec.ts
@@ -4,28 +4,28 @@ describe('compiler: transform v-slot', () => {
test('default slot', () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return {}
}`
)
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`test`,
- `test`,
+ `test`,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`test
`,
- `test`,
+ `test`,
`(_ctx, _cache) => {
return {}
}`
@@ -34,14 +34,14 @@ describe('compiler: transform v-slot', () => {
test('named slots', () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`{{error.message}}`,
- `{{v0.b}}`,
+ `{{v0.b}}`,
`(_ctx, _cache) => {
return { a: _w(({ data, loading, error, options }, s0, i0) => { return _e({ a: error }, error ? { b: _t(error.message) } : {}, { c: i0, d: s0 }); }, { name: 'd', path: 'a', vueId: '2a9ec0b0-0' }) }
}`
diff --git a/packages/uni-mp-compiler/src/template/codegen.ts b/packages/uni-mp-compiler/src/template/codegen.ts
index 1402231a3864cafbd43f2d27d8bafa44ed5ab1fc..ad6ce923af5a6564350fea6fbcd5f77b0e639256 100644
--- a/packages/uni-mp-compiler/src/template/codegen.ts
+++ b/packages/uni-mp-compiler/src/template/codegen.ts
@@ -422,14 +422,15 @@ function genDirectiveNode(
if (prop.name === 'slot') {
if (prop.arg) {
const arg = prop.arg as SimpleExpressionNode
-
- push(
- ` slot="${
- arg.isStatic
- ? dynamicSlotName(arg.content)
- : '{{' + arg.content + '}}'
- }"`
- )
+ if (arg.isStatic) {
+ const slotName = dynamicSlotName(arg.content)
+ // 非作用域默认插槽不生成 slot 属性
+ if (slotName !== SLOT_DEFAULT_NAME) {
+ push(` slot="${slotName}"`)
+ }
+ } else {
+ push(` slot="{{${arg.content}}}"`)
+ }
}
} else if (prop.name === 'show') {
let hiddenPropName = 'hidden'
diff --git a/packages/uni-mp-compiler/src/transforms/transformSlot.ts b/packages/uni-mp-compiler/src/transforms/transformSlot.ts
index 09aa6bba0e93978bc6db0529407745c0bfadcd8a..8155aaaaf8bd8ffb42b6e479805d2c305a627596 100644
--- a/packages/uni-mp-compiler/src/transforms/transformSlot.ts
+++ b/packages/uni-mp-compiler/src/transforms/transformSlot.ts
@@ -19,7 +19,7 @@ import { RENDER_SLOT } from '../runtimeHelpers'
import { genExpr } from '../codegen'
import { isScopedSlotVFor, isVForScope, TransformContext } from '../transform'
import { processProps } from './transformElement'
-import { rewriteExpression } from './utils'
+import { removeAttribute, rewriteExpression } from './utils'
import {
createAttributeNode,
createBindDirectiveNode,
@@ -102,6 +102,16 @@ export function rewriteSlot(node: SlotOutletNode, context: TransformContext) {
]),
context
)
+ } else {
+ // 非作用域默认插槽直接移除命名
+ if (slotName === `"${SLOT_DEFAULT_NAME}"`) {
+ removeAttribute(node, 'name')
+ }
+ }
+ } else {
+ // 非作用域默认插槽直接移除命名
+ if (slotName === `"${SLOT_DEFAULT_NAME}"`) {
+ removeAttribute(node, 'name')
}
}
}
diff --git a/packages/uni-mp-compiler/src/transforms/utils.ts b/packages/uni-mp-compiler/src/transforms/utils.ts
index 43b7b9c7190d440ef023c57f33a29c3addb647c7..f2f7d030c1dd540679a18bc857d8716ded59503d 100644
--- a/packages/uni-mp-compiler/src/transforms/utils.ts
+++ b/packages/uni-mp-compiler/src/transforms/utils.ts
@@ -16,6 +16,7 @@ import {
import { VUE_REF, VUE_REF_IN_FOR } from '@dcloudio/uni-cli-shared'
import {
createSimpleExpression,
+ ElementNode,
ExpressionNode,
NodeTypes,
SimpleExpressionNode,
@@ -189,3 +190,10 @@ function isReferencedByIds(node: Expression, knownIds: string[]) {
export function isStaticLiteral(value: object | null | undefined) {
return isLiteral(value) && !isTemplateLiteral(value)
}
+
+export function removeAttribute(node: ElementNode, name: string) {
+ const index = node.props.findIndex((prop) => prop.name === name)
+ if (index > -1) {
+ node.props.splice(index, 1)
+ }
+}
diff --git a/packages/uni-mp-compiler/src/transforms/vSlot.ts b/packages/uni-mp-compiler/src/transforms/vSlot.ts
index 83c421b1d206f5c03f71945446255bf70b10bf7b..2d030129c70f18da8d54c32544c16522f2b612f2 100644
--- a/packages/uni-mp-compiler/src/transforms/vSlot.ts
+++ b/packages/uni-mp-compiler/src/transforms/vSlot.ts
@@ -30,7 +30,6 @@ import {
import { dynamicSlotName, SLOT_DEFAULT_NAME } from '@dcloudio/uni-shared'
import {
createBindDirectiveNode,
- createDirectiveNode,
isUserComponent,
} from '@dcloudio/uni-cli-shared'
import { WITH_SCOPED_SLOT } from '../runtimeHelpers'
@@ -121,19 +120,6 @@ export const transformSlot: NodeTransform = (node, context) => {
)
transformTemplateSlotElement(onComponentSlot, templateNode, node, context)
node.children = [templateNode]
- } else {
- if (implicitDefaultChildren.length) {
- // test => test
- implicitDefaultChildren.forEach((child) => {
- node.children.splice(node.children.indexOf(child), 1)
- })
- node.children.unshift(
- createTemplateNode(
- createDirectiveNode('slot', 'default'),
- implicitDefaultChildren
- )
- )
- }
}
// 不支持 $slots, 则自动补充 props
if (slots.size && !context.miniProgram.slot.$slots) {
diff --git a/packages/uni-mp-kuaishou/dist/uni.mp.esm.js b/packages/uni-mp-kuaishou/dist/uni.mp.esm.js
index 86cf680b2dddeba537ce478f5ce87d00f03113db..5177333fabfad92b552a78b5093dd9bf195d7c7c 100644
--- a/packages/uni-mp-kuaishou/dist/uni.mp.esm.js
+++ b/packages/uni-mp-kuaishou/dist/uni.mp.esm.js
@@ -630,6 +630,18 @@ function initProps(mpComponentOptions) {
}
extend(mpComponentOptions.properties, initDefaultProps());
}
+const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
+function parsePropType(type, defaultValue) {
+ // [String]=>String
+ if (isArray(type) && type.length === 1) {
+ return type[0];
+ }
+ return type;
+}
+function normalizePropType(type, defaultValue) {
+ const res = parsePropType(type);
+ return PROP_TYPES.indexOf(res) !== -1 ? res : null;
+}
/**
* 初始化页面 props,方便接收页面参数,类型均为String,默认值均为''
* @param param
@@ -646,10 +658,26 @@ function initPageProps({ properties }, rawProps) {
}
else if (isPlainObject(rawProps)) {
Object.keys(rawProps).forEach((key) => {
- properties[key] = {
- type: String,
- value: '',
- };
+ const opts = rawProps[key];
+ if (isPlainObject(opts)) {
+ // title:{type:String,default:''}
+ let value = opts.default;
+ if (isFunction(value)) {
+ value = value();
+ }
+ const type = opts.type;
+ opts.type = normalizePropType(type);
+ properties[key] = {
+ type: opts.type,
+ value,
+ };
+ }
+ else {
+ // content:String
+ properties[key] = {
+ type: normalizePropType(opts),
+ };
+ }
});
}
}
diff --git a/packages/uni-mp-lark/dist/uni.mp.esm.js b/packages/uni-mp-lark/dist/uni.mp.esm.js
index 945912e9ead8abf38da133161d37fd1ef39ef45d..c97e9e9059cda574b29a94e17a2b9bdd2f10c34d 100644
--- a/packages/uni-mp-lark/dist/uni.mp.esm.js
+++ b/packages/uni-mp-lark/dist/uni.mp.esm.js
@@ -603,6 +603,18 @@ function initProps(mpComponentOptions) {
}
extend(mpComponentOptions.properties, initDefaultProps());
}
+const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
+function parsePropType(type, defaultValue) {
+ // [String]=>String
+ if (isArray(type) && type.length === 1) {
+ return type[0];
+ }
+ return type;
+}
+function normalizePropType(type, defaultValue) {
+ const res = parsePropType(type);
+ return PROP_TYPES.indexOf(res) !== -1 ? res : null;
+}
/**
* 初始化页面 props,方便接收页面参数,类型均为String,默认值均为''
* @param param
@@ -619,10 +631,26 @@ function initPageProps({ properties }, rawProps) {
}
else if (isPlainObject(rawProps)) {
Object.keys(rawProps).forEach((key) => {
- properties[key] = {
- type: String,
- value: '',
- };
+ const opts = rawProps[key];
+ if (isPlainObject(opts)) {
+ // title:{type:String,default:''}
+ let value = opts.default;
+ if (isFunction(value)) {
+ value = value();
+ }
+ const type = opts.type;
+ opts.type = normalizePropType(type);
+ properties[key] = {
+ type: opts.type,
+ value,
+ };
+ }
+ else {
+ // content:String
+ properties[key] = {
+ type: normalizePropType(opts),
+ };
+ }
});
}
}
diff --git a/packages/uni-mp-qq/dist/uni.mp.esm.js b/packages/uni-mp-qq/dist/uni.mp.esm.js
index 698953b67bbcda804bb85777022a053ecadca30e..16a1e2227e9a8a9c43a74856576e2b020eff422d 100644
--- a/packages/uni-mp-qq/dist/uni.mp.esm.js
+++ b/packages/uni-mp-qq/dist/uni.mp.esm.js
@@ -589,6 +589,18 @@ function initProps(mpComponentOptions) {
}
extend(mpComponentOptions.properties, initDefaultProps());
}
+const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
+function parsePropType(type, defaultValue) {
+ // [String]=>String
+ if (isArray(type) && type.length === 1) {
+ return type[0];
+ }
+ return type;
+}
+function normalizePropType(type, defaultValue) {
+ const res = parsePropType(type);
+ return PROP_TYPES.indexOf(res) !== -1 ? res : null;
+}
/**
* 初始化页面 props,方便接收页面参数,类型均为String,默认值均为''
* @param param
@@ -605,10 +617,26 @@ function initPageProps({ properties }, rawProps) {
}
else if (isPlainObject(rawProps)) {
Object.keys(rawProps).forEach((key) => {
- properties[key] = {
- type: String,
- value: '',
- };
+ const opts = rawProps[key];
+ if (isPlainObject(opts)) {
+ // title:{type:String,default:''}
+ let value = opts.default;
+ if (isFunction(value)) {
+ value = value();
+ }
+ const type = opts.type;
+ opts.type = normalizePropType(type);
+ properties[key] = {
+ type: opts.type,
+ value,
+ };
+ }
+ else {
+ // content:String
+ properties[key] = {
+ type: normalizePropType(opts),
+ };
+ }
});
}
}
diff --git a/packages/uni-mp-toutiao/dist/uni.mp.esm.js b/packages/uni-mp-toutiao/dist/uni.mp.esm.js
index f0df69a13e2357f35655767ec3bd8d0ffcfd1b0a..ded3997216cdec9d965cc848b1fdbce6c2a137ce 100644
--- a/packages/uni-mp-toutiao/dist/uni.mp.esm.js
+++ b/packages/uni-mp-toutiao/dist/uni.mp.esm.js
@@ -603,6 +603,18 @@ function initProps(mpComponentOptions) {
}
extend(mpComponentOptions.properties, initDefaultProps());
}
+const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
+function parsePropType(type, defaultValue) {
+ // [String]=>String
+ if (isArray(type) && type.length === 1) {
+ return type[0];
+ }
+ return type;
+}
+function normalizePropType(type, defaultValue) {
+ const res = parsePropType(type);
+ return PROP_TYPES.indexOf(res) !== -1 ? res : null;
+}
/**
* 初始化页面 props,方便接收页面参数,类型均为String,默认值均为''
* @param param
@@ -619,10 +631,26 @@ function initPageProps({ properties }, rawProps) {
}
else if (isPlainObject(rawProps)) {
Object.keys(rawProps).forEach((key) => {
- properties[key] = {
- type: String,
- value: '',
- };
+ const opts = rawProps[key];
+ if (isPlainObject(opts)) {
+ // title:{type:String,default:''}
+ let value = opts.default;
+ if (isFunction(value)) {
+ value = value();
+ }
+ const type = opts.type;
+ opts.type = normalizePropType(type);
+ properties[key] = {
+ type: opts.type,
+ value,
+ };
+ }
+ else {
+ // content:String
+ properties[key] = {
+ type: normalizePropType(opts),
+ };
+ }
});
}
}
diff --git a/packages/uni-quickapp-webview/dist/uni.mp.esm.js b/packages/uni-quickapp-webview/dist/uni.mp.esm.js
index 7c527c513bce962d7359dba0e2b1a143550d132f..8df645dfb7fd73852021797cd3c422a498bfd30d 100644
--- a/packages/uni-quickapp-webview/dist/uni.mp.esm.js
+++ b/packages/uni-quickapp-webview/dist/uni.mp.esm.js
@@ -581,6 +581,18 @@ function initProps(mpComponentOptions) {
}
extend(mpComponentOptions.properties, initDefaultProps());
}
+const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
+function parsePropType(type, defaultValue) {
+ // [String]=>String
+ if (isArray(type) && type.length === 1) {
+ return type[0];
+ }
+ return type;
+}
+function normalizePropType(type, defaultValue) {
+ const res = parsePropType(type);
+ return PROP_TYPES.indexOf(res) !== -1 ? res : null;
+}
/**
* 初始化页面 props,方便接收页面参数,类型均为String,默认值均为''
* @param param
@@ -597,10 +609,26 @@ function initPageProps({ properties }, rawProps) {
}
else if (isPlainObject(rawProps)) {
Object.keys(rawProps).forEach((key) => {
- properties[key] = {
- type: String,
- value: '',
- };
+ const opts = rawProps[key];
+ if (isPlainObject(opts)) {
+ // title:{type:String,default:''}
+ let value = opts.default;
+ if (isFunction(value)) {
+ value = value();
+ }
+ const type = opts.type;
+ opts.type = normalizePropType(type);
+ properties[key] = {
+ type: opts.type,
+ value,
+ };
+ }
+ else {
+ // content:String
+ properties[key] = {
+ type: normalizePropType(opts),
+ };
+ }
});
}
}