2020-05-16 22:20:26 +08:00
|
|
|
|
import { getOptionProps } from './props-util';
|
|
|
|
|
|
2018-01-12 16:10:41 +08:00
|
|
|
|
export default {
|
|
|
|
|
methods: {
|
2020-05-16 22:20:26 +08:00
|
|
|
|
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 || {}) };
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
Object.assign(this.$data, newState);
|
2020-03-07 19:45:13 +08:00
|
|
|
|
this.$forceUpdate();
|
2018-01-12 16:10:41 +08:00
|
|
|
|
this.$nextTick(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
callback && callback();
|
|
|
|
|
});
|
2018-01-12 16:10:41 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
__emit() {
|
|
|
|
|
// 直接调用listeners,底层组件不需要vueTool记录events
|
|
|
|
|
const args = [].slice.call(arguments, 0);
|
|
|
|
|
const eventName = args[0];
|
2020-03-29 16:07:02 +08:00
|
|
|
|
const event = this.$listeners[eventName];
|
|
|
|
|
if (args.length && event) {
|
|
|
|
|
if (Array.isArray(event)) {
|
|
|
|
|
for (let i = 0, l = event.length; i < l; i++) {
|
|
|
|
|
event[i](...args.slice(1));
|
|
|
|
|
}
|
2018-01-17 16:12:53 +08:00
|
|
|
|
} else {
|
2020-03-29 16:07:02 +08:00
|
|
|
|
event(...args.slice(1));
|
2018-01-17 16:12:53 +08:00
|
|
|
|
}
|
2018-01-12 16:10:41 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|