Skip to content

Commit

Permalink
fix: v-else events Meituan-Dianping#18
Browse files Browse the repository at this point in the history
  • Loading branch information
anchengjian committed Mar 9, 2018
1 parent 9d71421 commit 29c8b8a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/platforms/mp/compiler/mark-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function addAttr (path, key, value, inVdom) {
function mark (path, deps, iteratorArr = []) {
fixDefaultIterator(path)

const { tag, children, iterator1, events, directives } = path
const { tag, children, iterator1, events, directives, ifConditions } = path

const currentArr = Object.assign([], iteratorArr)

Expand All @@ -68,10 +68,19 @@ function mark (path, deps, iteratorArr = []) {
})
}

// fix: v-else events
if (ifConditions && ifConditions.length && !ifConditions._handled) {
ifConditions._handled = true
ifConditions.forEach((v, i) => {
mark(v.block, deps, currentArr)
})
}

// for mpvue-template-compiler
// events || v-model
const hasModel = directives && directives.find(v => v.name === 'model')
const needEventsID = events || hasModel

if (needEventsID) {
const eventId = getWxEleId(deps.eventIndex, currentArr)
// const eventId = getWxEleId(eIndex, currentArr)
Expand Down
7 changes: 7 additions & 0 deletions test/mp/compiler/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ describe('事件', () => {
{ name: 'a' }
)
})
it('v-else', () => {
assertCodegen(
`<div><div v-if="type === 'A'" @click="logger('A')">A</div><div v-else-if="type === 'B'" @click="logger('B')">B</div><div v-else-if="type === 'C'" @click="logger('C')">C</div><div v-else @click="logger('Not A/B/C')">Not A/B/C</div></div>`,
`<template name="a"><view class="_div"><view wx:if="{{type === 'A'}}" bindtap="handleProxy" data-eventid="{{'4'}}" data-comkey="{{$k}}" class="_div">A</view><view wx:elif="{{type === 'B'}}" bindtap="handleProxy" data-eventid="{{'1'}}" data-comkey="{{$k}}" class="_div">B</view><view wx:elif="{{type === 'C'}}" bindtap="handleProxy" data-eventid="{{'2'}}" data-comkey="{{$k}}" class="_div">C</view><view wx:else bindtap="handleProxy" data-eventid="{{'3'}}" data-comkey="{{$k}}" class="_div">Not A/B/C</view></view></template>`,
{ name: 'a' }
)
})
})

describe('表单', () => {
Expand Down

0 comments on commit 29c8b8a

Please sign in to comment.