Skip to content

Commit 08ba942

Browse files
committed
fix expressions on repeated items
1 parent 0dcf28e commit 08ba942

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

src/compiler.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,7 @@ CompilerProto.markComputed = function (binding) {
530530
vm = this.vm
531531
binding.isComputed = true
532532
// bind the accessors to the vm
533-
if (binding.isFn) {
534-
binding.value = utils.bind(value, vm)
535-
} else {
533+
if (!binding.isFn) {
536534
value.$get = utils.bind(value.$get, vm)
537535
if (value.$set) {
538536
value.$set = utils.bind(value.$set, vm)

src/directives/on.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module.exports = {
2929

3030
var compiler = this.compiler,
3131
event = this.arg,
32+
isExp = this.binding.isExp,
3233
ownerVM = this.binding.compiler.vm
3334

3435
if (compiler.repeat &&
@@ -51,7 +52,7 @@ module.exports = {
5152
if (target) {
5253
e.el = target
5354
e.targetVM = target.vue_viewmodel
54-
handler.call(ownerVM, e)
55+
handler.call(isExp ? e.targetVM : ownerVM, e)
5556
}
5657
}
5758
dHandler.event = event
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Repeated Expressions</title>
5+
<meta charset="utf-8">
6+
<script src="../../../dist/vue.js"></script>
7+
</head>
8+
<body>
9+
<ul id="test">
10+
<li
11+
v-repeat="items"
12+
v-on="click:n++"
13+
class="item-{{$index}}"
14+
>
15+
{{n}}
16+
</li>
17+
</ul>
18+
<script>
19+
var app = new Vue({
20+
el: '#test',
21+
data: {
22+
items: [
23+
{ n: 1 },
24+
{ n: 2 },
25+
{ n: 3 }
26+
]
27+
}
28+
})
29+
</script>
30+
</body>
31+
</html>

test/functional/specs/repeated-exp.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
casper.test.begin('Repeated Expressions', 3, function (test) {
2+
3+
casper
4+
.start('./fixtures/repeated-exp.html')
5+
.then(function () {
6+
this.click('.item-0')
7+
this.click('.item-1')
8+
this.click('.item-2')
9+
})
10+
.then(function () {
11+
test.assertSelectorHasText('.item-0', '2')
12+
test.assertSelectorHasText('.item-1', '3')
13+
test.assertSelectorHasText('.item-2', '4')
14+
})
15+
.run(function () {
16+
test.done()
17+
})
18+
19+
})

0 commit comments

Comments
 (0)