提交 8c30bd31 编写于 作者: Q qiang

fix(mp-alipay): handleProps before handleRef

上级 adcb22eb
import { handleProps } from './wrapper/util'
const MPComponent = Component
function initHook (name, options) {
const oldHook = options[name]
options[name] = function (...args) {
const props = this.props
if (props && props['data-com-type'] === 'wx') {
handleProps(this)
}
if (oldHook) {
return oldHook.apply(this, args)
}
}
}
if (!MPComponent.__$wrappered) {
MPComponent.__$wrappered = true
Component = function (options = {}) {
initHook('onInit', options)
return MPComponent(options)
}
}
......@@ -108,24 +108,24 @@ export function initChildVues (mpInstance) {
delete mpInstance._$childVues
}
function handleProps (ref) {
export function handleProps (ref) {
const eventProps = {}
let refProps = ref.props
const eventList = (refProps['data-event-list'] || '').split(',')
// 初始化支付宝小程序组件事件
eventList.forEach(key => {
const handler = refProps[key]
const res = key.match(/^on([A-Z])(\S*)/)
const event = res && (res[1].toLowerCase() + res[2])
refProps[key] = eventProps[key] = function () {
const props = Object.assign({}, refProps)
props[key] = handler
// 由于支付宝事件可能包含多个参数,不使用微信小程序事件格式
delete props['data-com-type']
triggerEvent.bind({ props })(event, {
__args__: [...arguments]
})
}
const handler = refProps[key]
const res = key.match(/^on([A-Z])(\S*)/)
const event = res && (res[1].toLowerCase() + res[2])
refProps[key] = eventProps[key] = function () {
const props = Object.assign({}, refProps)
props[key] = handler
// 由于支付宝事件可能包含多个参数,不使用微信小程序事件格式
delete props['data-com-type']
triggerEvent.bind({ props })(event, {
__args__: [...arguments]
})
}
})
// 处理 props 重写
Object.defineProperty(ref, 'props', {
......@@ -142,9 +142,6 @@ export function handleRef (ref) {
if (!(ref && this.$vm)) {
return
}
if (ref.props['data-com-type'] === 'wx') {
handleProps(ref)
}
const refName = ref.props['data-ref']
const refInForName = ref.props['data-ref-in-for']
if (refName) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册