mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-25 02:41:46 +08:00
chore(Tab): use callInterceptor (#7082)
This commit is contained in:
parent
d55585314f
commit
438d34caf1
@ -1,10 +1,11 @@
|
|||||||
// Utils
|
// Utils
|
||||||
import { createNamespace, isDef, addUnit, isPromise } from '../utils';
|
import { createNamespace, isDef, addUnit } from '../utils';
|
||||||
import { scrollLeftTo, scrollTopTo } from './utils';
|
import { scrollLeftTo, scrollTopTo } from './utils';
|
||||||
import { route } from '../utils/router';
|
import { route } from '../utils/router';
|
||||||
import { isHidden } from '../utils/dom/style';
|
import { isHidden } from '../utils/dom/style';
|
||||||
import { on, off } from '../utils/dom/event';
|
import { on, off } from '../utils/dom/event';
|
||||||
import { BORDER_TOP_BOTTOM } from '../utils/constant';
|
import { BORDER_TOP_BOTTOM } from '../utils/constant';
|
||||||
|
import { callInterceptor } from '../utils/interceptor';
|
||||||
import {
|
import {
|
||||||
getScroller,
|
getScroller,
|
||||||
getVisibleTop,
|
getVisibleTop,
|
||||||
@ -263,34 +264,21 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
callBeforeChange(name, done) {
|
|
||||||
if (this.beforeChange) {
|
|
||||||
const returnVal = this.beforeChange(name);
|
|
||||||
|
|
||||||
if (isPromise(returnVal)) {
|
|
||||||
returnVal.then((value) => {
|
|
||||||
if (value) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (returnVal) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// emit event when clicked
|
// emit event when clicked
|
||||||
onClick(item, index) {
|
onClick(item, index) {
|
||||||
const { title, disabled, computedName } = this.children[index];
|
const { title, disabled, computedName } = this.children[index];
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
this.$emit('disabled', computedName, title);
|
this.$emit('disabled', computedName, title);
|
||||||
} else {
|
} else {
|
||||||
this.callBeforeChange(computedName, () => {
|
callInterceptor({
|
||||||
|
interceptor: this.beforeChange,
|
||||||
|
args: [computedName],
|
||||||
|
done: () => {
|
||||||
this.setCurrentIndex(index);
|
this.setCurrentIndex(index);
|
||||||
this.scrollToCurrentContent();
|
this.scrollToCurrentContent();
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$emit('click', computedName, title);
|
this.$emit('click', computedName, title);
|
||||||
route(item.$router, item);
|
route(item.$router, item);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user