mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
[bugfix] Tab: props observer (#553)
This commit is contained in:
parent
0fe8d5f915
commit
c166c8e36c
8
dist/mixins/basic.js
vendored
8
dist/mixins/basic.js
vendored
@ -9,7 +9,13 @@ export const basic = Behavior({
|
|||||||
wx.createSelectorQuery()
|
wx.createSelectorQuery()
|
||||||
.in(this)[all ? 'selectAll' : 'select'](selector)
|
.in(this)[all ? 'selectAll' : 'select'](selector)
|
||||||
.boundingClientRect(rect => {
|
.boundingClientRect(rect => {
|
||||||
rect && resolve(rect);
|
if (all && Array.isArray(rect) && rect.length) {
|
||||||
|
resolve(rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!all && rect) {
|
||||||
|
resolve(rect);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.exec();
|
.exec();
|
||||||
});
|
});
|
||||||
|
11
dist/tab/index.js
vendored
11
dist/tab/index.js
vendored
@ -2,13 +2,22 @@ import { create } from '../common/create';
|
|||||||
|
|
||||||
create({
|
create({
|
||||||
props: {
|
props: {
|
||||||
disabled: Boolean,
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
observer() {
|
||||||
|
const parent = this.getRelationNodes('../tabs/index')[0];
|
||||||
|
if (parent) {
|
||||||
|
parent.updateTabs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
title: {
|
title: {
|
||||||
type: String,
|
type: String,
|
||||||
observer() {
|
observer() {
|
||||||
const parent = this.getRelationNodes('../tabs/index')[0];
|
const parent = this.getRelationNodes('../tabs/index')[0];
|
||||||
if (parent) {
|
if (parent) {
|
||||||
parent.setLine();
|
parent.setLine();
|
||||||
|
parent.updateTabs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
36
dist/tabs/index.js
vendored
36
dist/tabs/index.js
vendored
@ -5,21 +5,16 @@ create({
|
|||||||
'../tab/index': {
|
'../tab/index': {
|
||||||
type: 'descendant',
|
type: 'descendant',
|
||||||
|
|
||||||
linked(target) {
|
linked(child) {
|
||||||
const { tabs } = this.data;
|
this.data.tabs.push({
|
||||||
tabs.push({
|
instance: child,
|
||||||
instance: target,
|
data: child.data
|
||||||
data: target.data
|
|
||||||
});
|
});
|
||||||
this.setData({
|
this.updateTabs();
|
||||||
tabs,
|
|
||||||
scrollable: tabs.length > this.data.swipeThreshold
|
|
||||||
});
|
|
||||||
this.setActiveTab();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
unlinked(target) {
|
unlinked(child) {
|
||||||
const tabs = this.data.tabs.filter(item => item.instance !== target);
|
const tabs = this.data.tabs.filter(item => item.instance !== child);
|
||||||
this.setData({
|
this.setData({
|
||||||
tabs,
|
tabs,
|
||||||
scrollable: tabs.length > this.data.swipeThreshold
|
scrollable: tabs.length > this.data.swipeThreshold
|
||||||
@ -40,7 +35,8 @@ create({
|
|||||||
},
|
},
|
||||||
active: {
|
active: {
|
||||||
type: null,
|
type: null,
|
||||||
value: 0
|
value: 0,
|
||||||
|
observer: 'setActiveTab'
|
||||||
},
|
},
|
||||||
type: {
|
type: {
|
||||||
type: String,
|
type: String,
|
||||||
@ -73,6 +69,15 @@ create({
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
updateTabs() {
|
||||||
|
const { tabs } = this.data;
|
||||||
|
this.setData({
|
||||||
|
tabs,
|
||||||
|
scrollable: tabs.length > this.data.swipeThreshold
|
||||||
|
});
|
||||||
|
this.setActiveTab();
|
||||||
|
},
|
||||||
|
|
||||||
trigger(eventName, index) {
|
trigger(eventName, index) {
|
||||||
this.$emit(eventName, {
|
this.$emit(eventName, {
|
||||||
index,
|
index,
|
||||||
@ -95,8 +100,6 @@ create({
|
|||||||
this.trigger('change', active);
|
this.trigger('change', active);
|
||||||
this.setData({ active });
|
this.setData({ active });
|
||||||
this.setActiveTab();
|
this.setActiveTab();
|
||||||
this.setLine();
|
|
||||||
this.scrollIntoView();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -138,6 +141,9 @@ create({
|
|||||||
item.instance.setData(data);
|
item.instance.setData(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.setLine();
|
||||||
|
this.scrollIntoView();
|
||||||
},
|
},
|
||||||
|
|
||||||
// scroll active tab into view
|
// scroll active tab into view
|
||||||
|
@ -9,7 +9,13 @@ export const basic = Behavior({
|
|||||||
wx.createSelectorQuery()
|
wx.createSelectorQuery()
|
||||||
.in(this)[all ? 'selectAll' : 'select'](selector)
|
.in(this)[all ? 'selectAll' : 'select'](selector)
|
||||||
.boundingClientRect(rect => {
|
.boundingClientRect(rect => {
|
||||||
rect && resolve(rect);
|
if (all && Array.isArray(rect) && rect.length) {
|
||||||
|
resolve(rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!all && rect) {
|
||||||
|
resolve(rect);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.exec();
|
.exec();
|
||||||
});
|
});
|
||||||
|
@ -2,13 +2,22 @@ import { create } from '../common/create';
|
|||||||
|
|
||||||
create({
|
create({
|
||||||
props: {
|
props: {
|
||||||
disabled: Boolean,
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
observer() {
|
||||||
|
const parent = this.getRelationNodes('../tabs/index')[0];
|
||||||
|
if (parent) {
|
||||||
|
parent.updateTabs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
title: {
|
title: {
|
||||||
type: String,
|
type: String,
|
||||||
observer() {
|
observer() {
|
||||||
const parent = this.getRelationNodes('../tabs/index')[0];
|
const parent = this.getRelationNodes('../tabs/index')[0];
|
||||||
if (parent) {
|
if (parent) {
|
||||||
parent.setLine();
|
parent.setLine();
|
||||||
|
parent.updateTabs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,21 +5,16 @@ create({
|
|||||||
'../tab/index': {
|
'../tab/index': {
|
||||||
type: 'descendant',
|
type: 'descendant',
|
||||||
|
|
||||||
linked(target) {
|
linked(child) {
|
||||||
const { tabs } = this.data;
|
this.data.tabs.push({
|
||||||
tabs.push({
|
instance: child,
|
||||||
instance: target,
|
data: child.data
|
||||||
data: target.data
|
|
||||||
});
|
});
|
||||||
this.setData({
|
this.updateTabs();
|
||||||
tabs,
|
|
||||||
scrollable: tabs.length > this.data.swipeThreshold
|
|
||||||
});
|
|
||||||
this.setActiveTab();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
unlinked(target) {
|
unlinked(child) {
|
||||||
const tabs = this.data.tabs.filter(item => item.instance !== target);
|
const tabs = this.data.tabs.filter(item => item.instance !== child);
|
||||||
this.setData({
|
this.setData({
|
||||||
tabs,
|
tabs,
|
||||||
scrollable: tabs.length > this.data.swipeThreshold
|
scrollable: tabs.length > this.data.swipeThreshold
|
||||||
@ -40,7 +35,8 @@ create({
|
|||||||
},
|
},
|
||||||
active: {
|
active: {
|
||||||
type: null,
|
type: null,
|
||||||
value: 0
|
value: 0,
|
||||||
|
observer: 'setActiveTab'
|
||||||
},
|
},
|
||||||
type: {
|
type: {
|
||||||
type: String,
|
type: String,
|
||||||
@ -73,6 +69,15 @@ create({
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
updateTabs() {
|
||||||
|
const { tabs } = this.data;
|
||||||
|
this.setData({
|
||||||
|
tabs,
|
||||||
|
scrollable: tabs.length > this.data.swipeThreshold
|
||||||
|
});
|
||||||
|
this.setActiveTab();
|
||||||
|
},
|
||||||
|
|
||||||
trigger(eventName, index) {
|
trigger(eventName, index) {
|
||||||
this.$emit(eventName, {
|
this.$emit(eventName, {
|
||||||
index,
|
index,
|
||||||
@ -95,8 +100,6 @@ create({
|
|||||||
this.trigger('change', active);
|
this.trigger('change', active);
|
||||||
this.setData({ active });
|
this.setData({ active });
|
||||||
this.setActiveTab();
|
this.setActiveTab();
|
||||||
this.setLine();
|
|
||||||
this.scrollIntoView();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -138,6 +141,9 @@ create({
|
|||||||
item.instance.setData(data);
|
item.instance.setData(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.setLine();
|
||||||
|
this.scrollIntoView();
|
||||||
},
|
},
|
||||||
|
|
||||||
// scroll active tab into view
|
// scroll active tab into view
|
||||||
|
Loading…
x
Reference in New Issue
Block a user