diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
index 75d0c1f222b0a5c1e2135cea372cb511ed86b414..997db3ee8d03d763181dcd7a2be714c18392c1d5 100644
--- a/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
@@ -65,7 +65,7 @@ describe('mp:compiler-mp-alipay', () => {
)
assertCodegen(
'text',
- 'text',
+ 'text',
undefined,
undefined,
{
diff --git a/packages/uni-template-compiler/lib/script/traverse/data/index.js b/packages/uni-template-compiler/lib/script/traverse/data/index.js
index d4ca8e3bfa1999f5b1734f7bc0112eda7ac3f4fb..5d984dd96a2c17d66c71bf92f2f83c69e06f206a 100644
--- a/packages/uni-template-compiler/lib/script/traverse/data/index.js
+++ b/packages/uni-template-compiler/lib/script/traverse/data/index.js
@@ -52,12 +52,14 @@ module.exports = function traverseData (path, state, tagName) {
)
)
if (state.options.platform.name === 'mp-alipay') {
- addAttrProperties.push(
- t.objectProperty(
- t.stringLiteral('ref'),
- t.stringLiteral('__r')
+ if (!wxComponent.startsWith('plugin://')) {
+ addAttrProperties.push(
+ t.objectProperty(
+ t.stringLiteral('ref'),
+ t.stringLiteral('__r')
+ )
)
- )
+ }
const on = path.node.properties.find(prop => prop.key.name === 'on')
if (on) {
const properties = on.value.properties
diff --git a/packages/webpack-uni-mp-loader/lib/plugin/generate-component.js b/packages/webpack-uni-mp-loader/lib/plugin/generate-component.js
index 73fcbaa03408fdd4c85824609fe14a61807a2efe..3af845b626ad5ae509e65e84616157f535b36cb1 100644
--- a/packages/webpack-uni-mp-loader/lib/plugin/generate-component.js
+++ b/packages/webpack-uni-mp-loader/lib/plugin/generate-component.js
@@ -253,7 +253,7 @@ module.exports = function generateComponent (compilation, jsonpFunction = 'webpa
},
{
ext: 'js',
- source: 'Component({onInit(){this.props.onPluginWrap(this)},didUnmount(){this.props.onPluginWrap(this,false)}})'
+ source: 'Component({onInit(){this.props.onPluginWrap(this)},didUnmount(){this.props.onPluginWrap(this,true)}})'
},
{
ext: 'json',
diff --git a/packages/webpack-uni-mp-loader/lib/plugin/index-new.js b/packages/webpack-uni-mp-loader/lib/plugin/index-new.js
index 928739801ee6851a78263ac7ff5ed768ad7c3560..fdbcb3490df85dfc43f3261f2a12805e5c4e55a2 100644
--- a/packages/webpack-uni-mp-loader/lib/plugin/index-new.js
+++ b/packages/webpack-uni-mp-loader/lib/plugin/index-new.js
@@ -81,7 +81,7 @@ function addMPPluginRequire (compilation) {
const filePath = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, name))
const uniModuleId = modules.find(module => module.resource && normalizePath(module.resource) === filePath).id
- const source = orignalSource + `\nmodule.exports = ${globalEnv}.__webpack_require_UNI_MP_PLUGIN__('${uniModuleId}');\n`;
+ const source = orignalSource + `\nmodule.exports = ${globalEnv}.__webpack_require_UNI_MP_PLUGIN__('${uniModuleId}');\n`
compilation.assets[name] = {
size () {
diff --git a/src/platforms/mp-alipay/runtime/wrapper/util.js b/src/platforms/mp-alipay/runtime/wrapper/util.js
index bfa4757f4005da5b8a32019fade8f993ef503e4a..aa5d034b1e2bf3aeedbbf3831604328354a660cd 100644
--- a/src/platforms/mp-alipay/runtime/wrapper/util.js
+++ b/src/platforms/mp-alipay/runtime/wrapper/util.js
@@ -108,40 +108,44 @@ export function initChildVues (mpInstance) {
delete mpInstance._$childVues
}
+function handleProps (ref) {
+ const eventProps = {}
+ let refProps = ref.props
+ const eventList = refProps['data-event-list'].split(',')
+ // 初始化支付宝小程序组件事件
+ Object.keys(refProps).forEach(key => {
+ if (eventList.includes(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]
+ })
+ }
+ }
+ })
+ // 处理 props 重写
+ Object.defineProperty(ref, 'props', {
+ get () {
+ return refProps
+ },
+ set (value) {
+ refProps = Object.assign(value, eventProps)
+ }
+ })
+}
+
export function handleRef (ref) {
if (!ref) {
return
}
if (ref.props['data-com-type'] === 'wx') {
- const eventProps = {}
- let refProps = ref.props
- const eventList = refProps['data-event-list'].split(',')
- // 初始化支付宝小程序组件事件
- Object.keys(refProps).forEach(key => {
- if (eventList.includes(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]
- })
- }
- }
- })
- // 处理 props 重写
- Object.defineProperty(ref, 'props', {
- get () {
- return refProps
- },
- set (value) {
- refProps = Object.assign(value, eventProps)
- }
- })
+ handleProps(ref)
}
const refName = ref.props['data-ref']
const refInForName = ref.props['data-ref-in-for']
@@ -229,10 +233,12 @@ export const handleWrap = function (mp, destory) {
if (destory) {
delete this[key]
} else {
- // TODO remove handleRef
this[key] = function () {
mp.props[eventName].apply(this, arguments)
}
}
})
+ if (!destory) {
+ handleProps(mp)
+ }
}