Skip to content

Commit

Permalink
fix expressions on repeated items
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 15, 2014
1 parent 0dcf28e commit 08ba942
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,7 @@ CompilerProto.markComputed = function (binding) {
vm = this.vm
binding.isComputed = true
// bind the accessors to the vm
if (binding.isFn) {
binding.value = utils.bind(value, vm)
} else {
if (!binding.isFn) {
value.$get = utils.bind(value.$get, vm)
if (value.$set) {
value.$set = utils.bind(value.$set, vm)
Expand Down
3 changes: 2 additions & 1 deletion src/directives/on.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = {

var compiler = this.compiler,
event = this.arg,
isExp = this.binding.isExp,
ownerVM = this.binding.compiler.vm

if (compiler.repeat &&
Expand All @@ -51,7 +52,7 @@ module.exports = {
if (target) {
e.el = target
e.targetVM = target.vue_viewmodel
handler.call(ownerVM, e)
handler.call(isExp ? e.targetVM : ownerVM, e)
}
}
dHandler.event = event
Expand Down
31 changes: 31 additions & 0 deletions test/functional/fixtures/repeated-exp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Repeated Expressions</title>
<meta charset="utf-8">
<script src="../../../dist/vue.js"></script>
</head>
<body>
<ul id="test">
<li
v-repeat="items"
v-on="click:n++"
class="item-{{$index}}"
>
{{n}}
</li>
</ul>
<script>
var app = new Vue({
el: '#test',
data: {
items: [
{ n: 1 },
{ n: 2 },
{ n: 3 }
]
}
})
</script>
</body>
</html>
19 changes: 19 additions & 0 deletions test/functional/specs/repeated-exp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
casper.test.begin('Repeated Expressions', 3, function (test) {

casper
.start('./fixtures/repeated-exp.html')
.then(function () {
this.click('.item-0')
this.click('.item-1')
this.click('.item-2')
})
.then(function () {
test.assertSelectorHasText('.item-0', '2')
test.assertSelectorHasText('.item-1', '3')
test.assertSelectorHasText('.item-2', '4')
})
.run(function () {
test.done()
})

})

0 comments on commit 08ba942

Please sign in to comment.