-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathBaseMixin.js
41 lines (41 loc) · 1.36 KB
/
BaseMixin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
export default {
// directives: {
// ref: {
// bind: function (el, binding, vnode) {
// binding.value(vnode.componentInstance ? vnode.componentInstance : vnode.elm)
// },
// update: function (el, binding, vnode) {
// binding.value(vnode.componentInstance ? vnode.componentInstance : vnode.elm)
// },
// unbind: function (el, binding, vnode) {
// binding.value(null)
// },
// },
// },
methods: {
setState(state, callback) {
const newState = typeof state === 'function' ? state(this.$data, this.$props) : state;
// if (this.getDerivedStateFromProps) {
// Object.assign(newState, this.getDerivedStateFromProps(getOptionProps(this), { ...this.$data, ...newState }, true) || {})
// }
Object.assign(this.$data, newState);
this.$forceUpdate();
this.$nextTick(() => {
callback && callback();
});
},
__emit() {
// 直接调用listeners,底层组件不需要vueTool记录events
const args = [].slice.call(arguments, 0);
const filterEvent = [];
const eventName = args[0];
if (args.length && this.$listeners[eventName]) {
if (filterEvent.includes(eventName)) {
this.$emit(eventName, ...args.slice(1));
} else {
this.$listeners[eventName](...args.slice(1));
}
}
},
},
};