Skip to content

Commit e6e3b53

Browse files
committed
fix: #283
1 parent d46fdb3 commit e6e3b53

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/platforms/mp/compiler/codegen/convert/attrs.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,15 @@ export default {
115115
wxmlEventName = eventMap.map[eventName]
116116
}
117117

118-
wxmlEventName = (eventNameMap.includes('stop') ? 'catch' : 'bind') + (wxmlEventName || eventName)
118+
let eventType = 'bind'
119+
const isStop = eventNameMap.includes('stop')
120+
if (eventNameMap.includes('capture')) {
121+
eventType = isStop ? 'capture-catch:' : 'capture-bind:'
122+
} else if (isStop) {
123+
eventType = 'catch'
124+
}
125+
126+
wxmlEventName = eventType + (wxmlEventName || eventName)
119127
attrs[wxmlEventName] = 'handleProxy'
120128

121129
return attrs

test/mp/compiler/index.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,30 @@ describe('事件', () => {
320320
)
321321
})
322322

323+
it('@click.stop', () => {
324+
assertCodegen(
325+
`<a @click.stop="ddd"></a>`,
326+
`<template name="a"><view catchtap="handleProxy" data-eventid="{{'0'}}" data-comkey="{{$k}}" class="_a"></view></template>`,
327+
{ name: 'a' }
328+
)
329+
})
330+
331+
it('@click.stop.capture', () => {
332+
assertCodegen(
333+
`<a @click.stop.capture="ddd"></a>`,
334+
`<template name="a"><view capture-catch:tap="handleProxy" data-eventid="{{'0'}}" data-comkey="{{$k}}" class="_a"></view></template>`,
335+
{ name: 'a' }
336+
)
337+
})
338+
339+
it('@click.capture', () => {
340+
assertCodegen(
341+
`<a @click.capture="ddd"></a>`,
342+
`<template name="a"><view capture-bind:tap="handleProxy" data-eventid="{{'0'}}" data-comkey="{{$k}}" class="_a"></view></template>`,
343+
{ name: 'a' }
344+
)
345+
})
346+
323347
it('@load', () => {
324348
assertCodegen(
325349
`<a @load="ddd"></a>`,

0 commit comments

Comments
 (0)