data作为函数时也需要callthis
This commit is contained in:
parent
44868cb150
commit
628da7aa96
|
|
@ -505,7 +505,7 @@ function createComponent(option, features) {
|
|||
ready: function () {
|
||||
if (typeof data === 'function') {
|
||||
// ts的编译好像有问题,这里不硬写as过不去
|
||||
var data2 = data({ features: features, props: this.data });
|
||||
var data2 = data.call(this);
|
||||
this.setData(data2);
|
||||
}
|
||||
ready && ready.call(this);
|
||||
|
|
|
|||
|
|
@ -537,8 +537,7 @@ function createComponent(option, features) {
|
|||
_loop_1(m);
|
||||
}
|
||||
}
|
||||
// ts似乎有个BUG,这里不硬写as会有编译错误
|
||||
var data2 = typeof data === 'function' ? data({ features: features, props: props }) : data;
|
||||
var data2 = typeof data === 'function' ? data.call(_this) : data;
|
||||
_this.state = Object.assign({}, data2, {
|
||||
oakLoading: false,
|
||||
oakLoadingMore: false,
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ export declare type ComponentPublicThisType<ED extends EntityDict & BaseEntityDi
|
|||
subscribed: Array<() => void>;
|
||||
features: FD & BasicFeatures<ED, Cxt, FrontCxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
state: ComponentData<ED, T, FormedData, TData>;
|
||||
props: ComponentProps<IsList, TProperty>;
|
||||
props: Readonly<ComponentProps<IsList, TProperty>>;
|
||||
setState: (data: Partial<ComponentData<ED, T, FormedData, TData>>, callback?: () => void) => void;
|
||||
triggerEvent: <DetailType = any>(name: string, detail?: DetailType, options?: WechatMiniprogram.Component.TriggerEventOption) => void;
|
||||
} & TMethod & OakCommonComponentMethods<ED, T> & OakListComponentMethods<ED, T> & OakSingleComponentMethods<ED, T>;
|
||||
|
|
|
|||
|
|
@ -762,7 +762,7 @@ export function createComponent<
|
|||
ready() {
|
||||
if (typeof data === 'function') {
|
||||
// ts的编译好像有问题,这里不硬写as过不去
|
||||
const data2 = (data as ((option: { features: BasicFeatures<ED, Cxt, FrontCxt, AD & CommonAspectDict<ED, Cxt>> & FD, props: ComponentProps<IsList, TProperty>}) => TData))({ features, props: this.data as any });
|
||||
const data2 = (data as Function).call(this as any);
|
||||
this.setData(data2);
|
||||
}
|
||||
ready && ready.call(this);
|
||||
|
|
|
|||
|
|
@ -792,8 +792,7 @@ export function createComponent<
|
|||
}
|
||||
}
|
||||
|
||||
// ts似乎有个BUG,这里不硬写as会有编译错误
|
||||
const data2 = typeof data === 'function' ? (data as ((option: { features: BasicFeatures<ED, Cxt, FrontCxt, AD & CommonAspectDict<ED, Cxt>> & FD, props: ComponentProps<IsList, TProperty> }) => TData))({ features, props }) : data;
|
||||
const data2 = typeof data === 'function' ? (data as Function).call(this as any) : data;
|
||||
this.state = Object.assign({}, data2, {
|
||||
oakLoading: false,
|
||||
oakLoadingMore: false,
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ export type ComponentPublicThisType<
|
|||
subscribed: Array<() => void>;
|
||||
features: FD & BasicFeatures<ED, Cxt, FrontCxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
state: ComponentData<ED, T, FormedData, TData>;
|
||||
props: ComponentProps<IsList, TProperty>;
|
||||
props: Readonly<ComponentProps<IsList, TProperty>>;
|
||||
setState: (
|
||||
data: Partial<ComponentData<ED, T, FormedData, TData>>,
|
||||
callback?: () => void,
|
||||
|
|
|
|||
Loading…
Reference in New Issue