mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[bugfix] functional component should not inherit scropedSlots (#2752)
This commit is contained in:
parent
137fe83fc1
commit
170dcbf0d2
@ -1,4 +1,5 @@
|
|||||||
import { use, isDef } from '../utils';
|
import { use, isDef } from '../utils';
|
||||||
|
import { inherit } from '../utils/functional';
|
||||||
import Tag from '../tag';
|
import Tag from '../tag';
|
||||||
|
|
||||||
const [sfc, bem] = use('card');
|
const [sfc, bem] = use('card');
|
||||||
@ -68,7 +69,7 @@ function Card(h, props, slots, ctx) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={bem()} {...ctx.data}>
|
<div class={bem()} {...inherit(ctx, true)}>
|
||||||
<div class={bem('header')}>
|
<div class={bem('header')}>
|
||||||
{Thumb}
|
{Thumb}
|
||||||
<div class={bem('content', { centered: props.centered })}>
|
<div class={bem('content', { centered: props.centered })}>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { use } from '../utils';
|
import { use } from '../utils';
|
||||||
|
import { inherit } from '../utils/functional';
|
||||||
|
|
||||||
const [sfc, bem] = use('cell-group');
|
const [sfc, bem] = use('cell-group');
|
||||||
|
|
||||||
@ -6,7 +7,7 @@ function CellGroup(h, props, slots, ctx) {
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
class={[bem(), { 'van-hairline--top-bottom': props.border }]}
|
class={[bem(), { 'van-hairline--top-bottom': props.border }]}
|
||||||
{...ctx.data}
|
{...inherit(ctx, true)}
|
||||||
>
|
>
|
||||||
{slots.default && slots.default()}
|
{slots.default && slots.default()}
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { use } from '../utils';
|
import { use } from '../utils';
|
||||||
|
import { inherit } from '../utils/functional';
|
||||||
|
|
||||||
const [sfc, bem] = use('goods-action');
|
const [sfc, bem] = use('goods-action');
|
||||||
|
|
||||||
function GoodsAction(h, props, slots, ctx) {
|
function GoodsAction(h, props, slots, ctx) {
|
||||||
return (
|
return (
|
||||||
<div class={bem()} {...ctx.data}>
|
<div class={bem()} {...inherit(ctx, true)}>
|
||||||
{slots.default && slots.default()}
|
{slots.default && slots.default()}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { use } from '../utils';
|
import { use } from '../utils';
|
||||||
|
import { inherit } from '../utils/functional';
|
||||||
import Info from '../info';
|
import Info from '../info';
|
||||||
import isSrc from '../utils/validate/src';
|
import isSrc from '../utils/validate/src';
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ function Icon(h, props, slots, ctx) {
|
|||||||
color: props.color,
|
color: props.color,
|
||||||
fontSize: props.size
|
fontSize: props.size
|
||||||
}}
|
}}
|
||||||
{...ctx.data}
|
{...inherit(ctx, true)}
|
||||||
>
|
>
|
||||||
{ctx.default && ctx.default()}
|
{ctx.default && ctx.default()}
|
||||||
{urlIcon && <img src={props.name} />}
|
{urlIcon && <img src={props.name} />}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import { use, isDef } from '../utils';
|
import { use, isDef } from '../utils';
|
||||||
|
import { inherit } from '../utils/functional';
|
||||||
|
|
||||||
const [sfc, bem] = use('info');
|
const [sfc, bem] = use('info');
|
||||||
|
|
||||||
function Info(h, props, slots, ctx) {
|
function Info(h, props, slots, ctx) {
|
||||||
return (
|
return (
|
||||||
isDef(props.info) && (
|
isDef(props.info) && (
|
||||||
<div class={bem()} {...ctx.data}>
|
<div class={bem()} {...inherit(ctx, true)}>
|
||||||
{props.info}
|
{props.info}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { use } from '../utils';
|
import { use } from '../utils';
|
||||||
|
import { inherit } from '../utils/functional';
|
||||||
|
|
||||||
const [sfc, bem] = use('loading');
|
const [sfc, bem] = use('loading');
|
||||||
const DEFAULT_COLOR = '#c9c9c9';
|
const DEFAULT_COLOR = '#c9c9c9';
|
||||||
@ -28,7 +29,7 @@ function Loading(h, props, slots, ctx) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={bem([type, colorType])} style={style} {...ctx.data}>
|
<div class={bem([type, colorType])} style={style} {...inherit(ctx, true)}>
|
||||||
<span class={bem('spinner', type)}>
|
<span class={bem('spinner', type)}>
|
||||||
{Spin}
|
{Spin}
|
||||||
{Circular}
|
{Circular}
|
||||||
|
@ -1,29 +1,36 @@
|
|||||||
import { use } from '../utils';
|
import { use } from '../utils';
|
||||||
import Cell from '../cell';
|
import Cell from '../cell';
|
||||||
import CellGroup from '../cell-group';
|
import CellGroup from '../cell-group';
|
||||||
|
import { inherit } from '../utils/functional';
|
||||||
|
|
||||||
const [sfc, bem] = use('panel');
|
const [sfc, bem] = use('panel');
|
||||||
|
|
||||||
function Panel(h, props, slots, ctx) {
|
function Panel(h, props, slots, ctx) {
|
||||||
|
const Content = () => [
|
||||||
|
slots.header ? (
|
||||||
|
slots.header()
|
||||||
|
) : (
|
||||||
|
<Cell
|
||||||
|
icon={props.icon}
|
||||||
|
label={props.desc}
|
||||||
|
title={props.title}
|
||||||
|
value={props.status}
|
||||||
|
class={bem('header')}
|
||||||
|
valueClass={bem('header-value')}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
<div class={bem('content')}>{slots.default && slots.default()}</div>,
|
||||||
|
slots.footer && (
|
||||||
|
<div class={[bem('footer'), 'van-hairline--top']}>{slots.footer()}</div>
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CellGroup class={bem()} {...ctx.data}>
|
<CellGroup
|
||||||
{slots.header ? (
|
class={bem()}
|
||||||
slots.header()
|
scopedSlots={{ default: Content }}
|
||||||
) : (
|
{...inherit(ctx, true)}
|
||||||
<Cell
|
/>
|
||||||
icon={props.icon}
|
|
||||||
label={props.desc}
|
|
||||||
title={props.title}
|
|
||||||
value={props.status}
|
|
||||||
class={bem('header')}
|
|
||||||
valueClass={bem('header-value')}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<div class={bem('content')}>{slots.default && slots.default()}</div>
|
|
||||||
{slots.footer && (
|
|
||||||
<div class={[bem('footer'), 'van-hairline--top']}>{slots.footer()}</div>
|
|
||||||
)}
|
|
||||||
</CellGroup>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { use } from '../utils';
|
import { use } from '../utils';
|
||||||
import { emit } from '../utils/functional';
|
import { emit, inherit } from '../utils/functional';
|
||||||
|
|
||||||
const [sfc, bem] = use('password-input');
|
const [sfc, bem] = use('password-input');
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ function PasswordInput(h, props, slots, ctx) {
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
emit(ctx, 'focus', event);
|
emit(ctx, 'focus', event);
|
||||||
}}
|
}}
|
||||||
{...ctx.data}
|
{...inherit(ctx, true)}
|
||||||
>
|
>
|
||||||
{Points}
|
{Points}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { use } from '../utils';
|
import { use } from '../utils';
|
||||||
|
import { inherit } from '../utils/functional';
|
||||||
import { RED, BLUE, GREEN, GRAY_DARK } from '../utils/color';
|
import { RED, BLUE, GREEN, GRAY_DARK } from '../utils/color';
|
||||||
|
|
||||||
const [sfc, bem] = use('tag');
|
const [sfc, bem] = use('tag');
|
||||||
@ -29,7 +30,7 @@ function Tag(h, props, slots, ctx) {
|
|||||||
'van-hairline--surround': plain
|
'van-hairline--surround': plain
|
||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
{...ctx.data}
|
{...inherit(ctx, true)}
|
||||||
>
|
>
|
||||||
{slots.default && slots.default()}
|
{slots.default && slots.default()}
|
||||||
</span>
|
</span>
|
||||||
|
@ -21,8 +21,8 @@ const inheritKey = [
|
|||||||
const mapInheritKey: ObjectIndex = { nativeOn: 'on' };
|
const mapInheritKey: ObjectIndex = { nativeOn: 'on' };
|
||||||
|
|
||||||
// inherit partial context, map nativeOn to on
|
// inherit partial context, map nativeOn to on
|
||||||
export function inherit(context: Context): InheritContext {
|
export function inherit(context: Context, inheritListeners: boolean): InheritContext {
|
||||||
return inheritKey.reduce(
|
const result = inheritKey.reduce(
|
||||||
(obj, key) => {
|
(obj, key) => {
|
||||||
if (context.data[key]) {
|
if (context.data[key]) {
|
||||||
obj[mapInheritKey[key] || key] = context.data[key];
|
obj[mapInheritKey[key] || key] = context.data[key];
|
||||||
@ -31,6 +31,13 @@ export function inherit(context: Context): InheritContext {
|
|||||||
},
|
},
|
||||||
{} as InheritContext
|
{} as InheritContext
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (inheritListeners) {
|
||||||
|
result.on = result.on || {};
|
||||||
|
Object.assign(result.on, context.data.on);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// emit event
|
// emit event
|
||||||
|
Loading…
x
Reference in New Issue
Block a user