mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-09-10 14:59:46 +08:00
refactor(Common): refactor set method with nextTick (#2561)
This commit is contained in:
parent
fc2fdb9f11
commit
7165b399c7
@ -1,5 +1,7 @@
|
|||||||
import { VantComponent } from '../common/component';
|
import { VantComponent } from '../common/component';
|
||||||
|
|
||||||
|
type TrivialInstance = WechatMiniprogram.Component.TrivialInstance;
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
relation: {
|
relation: {
|
||||||
name: 'collapse-item',
|
name: 'collapse-item',
|
||||||
@ -9,7 +11,7 @@ VantComponent({
|
|||||||
},
|
},
|
||||||
unlinked(child) {
|
unlinked(child) {
|
||||||
this.children = this.children.filter(
|
this.children = this.children.filter(
|
||||||
(item: WechatMiniprogram.Component.TrivialInstance) => item !== child
|
(item: TrivialInstance) => item !== child
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -35,7 +37,7 @@ VantComponent({
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
updateExpanded() {
|
updateExpanded() {
|
||||||
this.children.forEach((child: WechatMiniprogram.Component.TrivialInstance) => {
|
this.children.forEach((child: TrivialInstance) => {
|
||||||
child.updateExpanded();
|
child.updateExpanded();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -1,14 +1,9 @@
|
|||||||
export const behavior = Behavior({
|
export const behavior = Behavior({
|
||||||
methods: {
|
methods: {
|
||||||
set(data: object, callback: Function) {
|
set(data: object, callback: Function) {
|
||||||
return new Promise(resolve => {
|
this.setData(data, callback);
|
||||||
this.setData(data, () => {
|
|
||||||
if (callback && typeof callback === 'function') {
|
return new Promise(resolve => wx.nextTick(resolve));
|
||||||
callback.call(this);
|
|
||||||
}
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import { VantComponent } from '../common/component';
|
import { VantComponent } from '../common/component';
|
||||||
|
|
||||||
|
type TrivialInstance = WechatMiniprogram.Component.TrivialInstance;
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
relation: {
|
relation: {
|
||||||
name: 'tabbar-item',
|
name: 'tabbar-item',
|
||||||
@ -11,7 +13,7 @@ VantComponent({
|
|||||||
},
|
},
|
||||||
unlinked(target) {
|
unlinked(target) {
|
||||||
this.children = this.children.filter(
|
this.children = this.children.filter(
|
||||||
(item: WechatMiniprogram.Component.TrivialInstance) => item !== target
|
(item: TrivialInstance) => item !== target
|
||||||
);
|
);
|
||||||
this.updateChildren();
|
this.updateChildren();
|
||||||
}
|
}
|
||||||
@ -60,11 +62,11 @@ VantComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
children.map((child: WechatMiniprogram.Component.TrivialInstance) => child.updateFromParent())
|
children.map((child: TrivialInstance) => child.updateFromParent())
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
onChange(child: WechatMiniprogram.Component.TrivialInstance) {
|
onChange(child: TrivialInstance) {
|
||||||
const index = this.children.indexOf(child);
|
const index = this.children.indexOf(child);
|
||||||
const active = child.data.name || index;
|
const active = child.data.name || index;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user