You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/_util/BaseMixin.js

45 lines
1.3 KiB

import { nextTick } from 'vue';
import { getOptionProps } from './props-util';
7 years ago
export default {
methods: {
setState(state = {}, callback) {
let newState = typeof state === 'function' ? state(this.$data, this.$props) : state;
if (this.getDerivedStateFromProps) {
const s = this.getDerivedStateFromProps(getOptionProps(this), {
...this.$data,
...newState,
});
if (s === null) {
return;
} else {
newState = { ...newState, ...(s || {}) };
}
}
Object.assign(this.$data, newState);
if (this._.isMounted) {
this.$forceUpdate();
}
nextTick(() => {
callback && callback();
});
7 years ago
},
__emit() {
// 直接调用事件底层组件不需要vueTool记录events
const args = [].slice.call(arguments, 0);
let eventName = args[0];
eventName = `on${eventName[0].toUpperCase()}${eventName.substring(1)}`;
const event = this.$props[eventName] || this.$attrs[eventName];
if (args.length && event) {
if (Array.isArray(event)) {
for (let i = 0, l = event.length; i < l; i++) {
event[i](...args.slice(1));
}
7 years ago
} else {
event(...args.slice(1));
7 years ago
}
7 years ago
}
},
},
};