Skip to content

Commit

Permalink
fix: 兜底data-event-list 属性为 undefined 的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
EAGzzyCSL authored and zhetengbiji committed Oct 13, 2022
1 parent 36c9f21 commit 1d55302
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/platforms/mp-alipay/runtime/wrapper/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export function initChildVues (mpInstance) {
function handleProps (ref) {
const eventProps = {}
let refProps = ref.props
const eventList = refProps['data-event-list'].split(',')
const eventList = (refProps['data-event-list'] || '').split(',')
// 初始化支付宝小程序组件事件
Object.keys(refProps).forEach(key => {
if (eventList.includes(key)) {
Expand Down Expand Up @@ -227,7 +227,7 @@ export const handleLink = (function () {

export const handleWrap = function (mp, destory) {
const vueId = mp.props.vueId
const list = mp.props['data-event-list'].split(',')
const list = (mp.props['data-event-list'] || '').split(',')
list.forEach(eventName => {
const key = `${eventName}${vueId}`
if (destory) {
Expand Down
104 changes: 52 additions & 52 deletions src/platforms/mp-xhs/runtime/wrapper/util.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
import {
isFn,
hasOwn
} from 'uni-shared'

export const isComponent2 = xhs.canIUse('component2')

export const mocks = ['$id']

export function initSpecialMethods (mpInstance) {
if (!mpInstance.$vm) {
return
}
let path = mpInstance.is || mpInstance.route
if (!path) {
return
}
if (path.indexOf('/') === 0) {
path = path.substr(1)
}
const specialMethods = xhs.specialMethods && xhs.specialMethods[path]
if (specialMethods) {
specialMethods.forEach(method => {
if (isFn(mpInstance.$vm[method])) {
mpInstance[method] = function (event) {
if (hasOwn(event, 'markerId')) {
event.detail = typeof event.detail === 'object' ? event.detail : {}
event.detail.markerId = event.markerId
}
// TODO normalizeEvent
mpInstance.$vm[method](event)
}
}
})
}
}

export const handleWrap = function (mp, destory) {
const vueId = mp.props.vueId
const list = mp.props['data-event-list'].split(',')
list.forEach(eventName => {
const key = `${eventName}${vueId}`
if (destory) {
delete this[key]
} else {
// TODO remove handleRef
this[key] = function () {
mp.props[eventName].apply(this, arguments)
}
}
})
}
import {
isFn,
hasOwn
} from 'uni-shared'

export const isComponent2 = xhs.canIUse('component2')

export const mocks = ['$id']

export function initSpecialMethods (mpInstance) {
if (!mpInstance.$vm) {
return
}
let path = mpInstance.is || mpInstance.route
if (!path) {
return
}
if (path.indexOf('/') === 0) {
path = path.substr(1)
}
const specialMethods = xhs.specialMethods && xhs.specialMethods[path]
if (specialMethods) {
specialMethods.forEach(method => {
if (isFn(mpInstance.$vm[method])) {
mpInstance[method] = function (event) {
if (hasOwn(event, 'markerId')) {
event.detail = typeof event.detail === 'object' ? event.detail : {}
event.detail.markerId = event.markerId
}
// TODO normalizeEvent
mpInstance.$vm[method](event)
}
}
})
}
}

export const handleWrap = function (mp, destory) {
const vueId = mp.props.vueId
const list = (mp.props['data-event-list'] || '').split(',')
list.forEach(eventName => {
const key = `${eventName}${vueId}`
if (destory) {
delete this[key]
} else {
// TODO remove handleRef
this[key] = function () {
mp.props[eventName].apply(this, arguments)
}
}
})
}

0 comments on commit 1d55302

Please sign in to comment.