Skip to content

Commit

Permalink
fix(taro-quickapp): 兼容各种事件绑定传参情况
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Jul 11, 2019
1 parent 6b48d95 commit 6cda94c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions packages/taro-quickapp/src/component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
internal_safe_get as safeGet
} from '@tarojs/taro'

import { enqueueRender } from './render-queue'
import { updateComponent } from './lifecycle'

Expand Down Expand Up @@ -94,11 +95,12 @@ export default class BaseComponent {
__arguments: args
}
const detail = {}
if (this.$scope._externalBinding) {
const tempalateAttr = this.$scope._externalBinding.template.attr
Object.keys(tempalateAttr).forEach(item => {
const externalBinding = this.$scope._externalBinding
const attr = this.$scope._attr || this.$scope.attr || (externalBinding && externalBinding.template.attr)
if (attr) {
Object.keys(attr).forEach(item => {
if (/^data/.test(item)) {
detail[item.replace(/^data/, '')] = tempalateAttr[item]
detail[item.replace(/_/g, '').replace(/^data/, '')] = typeof attr[item] === 'function' ? attr[item]() : attr[item]
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions packages/taro-quickapp/src/create-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function processEvent (eventHandlerName, obj) {
const dataset = {}
const currentTarget = event.currentTarget
const vm = currentTarget._vm || (currentTarget._target ? currentTarget._target._vm : null)
const attr = vm ? vm._externalBinding.template.attr : currentTarget._attr
const attr = vm ? vm._externalBinding.template.attr : (currentTarget._attr || currentTarget.attr)
if (attr) {
Object.keys(attr).forEach(key => {
if (/^data/.test(key)) {
Expand Down Expand Up @@ -330,6 +330,6 @@ export default function createComponent (ComponentClass, isPage) {
}
bindStaticFns(componentConf, ComponentClass)
bindProperties(componentConf, ComponentClass)
ComponentClass['$$events'] && bindEvents(componentConf, ComponentClass['$$events'])
ComponentClass['taroPrivateEvents'] && bindEvents(componentConf, ComponentClass['taroPrivateEvents'])
return componentConf
}

0 comments on commit 6cda94c

Please sign in to comment.