2018-09-05 21:28:54 +08:00
|
|
|
|
import { getOptionProps } from './props-util'
|
|
|
|
|
|
2018-01-12 16:10:41 +08:00
|
|
|
|
export default {
|
2018-09-05 21:28:54 +08:00
|
|
|
|
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)
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-01-12 16:10:41 +08:00
|
|
|
|
methods: {
|
|
|
|
|
setState (state, callback) {
|
2018-09-05 21:28:54 +08:00
|
|
|
|
const newState = typeof state === 'function' ? state(this.$data) : state
|
|
|
|
|
if (this.getDerivedStateFromProps) {
|
|
|
|
|
Object.assign(newState, this.getDerivedStateFromProps(getOptionProps(this), this.$data, true) || {})
|
|
|
|
|
}
|
|
|
|
|
Object.assign(this.$data, newState)
|
2018-01-12 16:10:41 +08:00
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
callback && callback()
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
__emit () { // 直接调用listeners,底层组件不需要vueTool记录events
|
|
|
|
|
const args = [].slice.call(arguments, 0)
|
2018-01-17 16:12:53 +08:00
|
|
|
|
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))
|
|
|
|
|
}
|
2018-01-12 16:10:41 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|