-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A computed property can depend on properties on repeated items. When new items are added to the Array, the dependency collection has already been done so their properties are not collected by the computed property on the parent. We need to re-parse the dependencies in such situation, namely push, unshift, splice and when the entire Array is swapped. Also included casper test case by @daines.
- Loading branch information
Showing
5 changed files
with
113 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Repeated form elements</title> | ||
<meta charset="utf-8"> | ||
<script src="../../../dist/vue.js"></script> | ||
</head> | ||
<body> | ||
<form id="form"> | ||
<p v-repeat="items"> | ||
<input type="text" name="text{{$index}}" v-model="text"> | ||
</p> | ||
<button v-on="click: add" id="add">Add</button> | ||
<p id="texts">{{texts}}</p> | ||
</form> | ||
<script> | ||
var app = new Vue({ | ||
el: '#form', | ||
data: { | ||
items: [ | ||
{ text: "a" }, | ||
{ text: "b" } | ||
] | ||
}, | ||
methods: { | ||
add: function(e) { | ||
this.items.push({ text: "c" }) | ||
e.preventDefault() | ||
} | ||
}, | ||
computed: { | ||
texts: function () { | ||
return this.items.map(function(item) { | ||
return item.text | ||
}).join(",") | ||
} | ||
} | ||
}) | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
casper.test.begin('Computed property depending on repeated items', 4, function (test) { | ||
|
||
casper | ||
.start('./fixtures/computed-repeat.html') | ||
.then(function () { | ||
test.assertSelectorHasText('#texts', 'a,b') | ||
}) | ||
.thenClick('#add', function () { | ||
test.assertSelectorHasText('#texts', 'a,b,c') | ||
}) | ||
.then(function () { | ||
this.fill('#form', { | ||
"text0": 'd', | ||
"text1": 'e', | ||
"text2": 'f', | ||
}) | ||
}) | ||
.then(function () { | ||
this.sendKeys('input[name="text2"]', 'fff') | ||
}) | ||
.then(function () { | ||
test.assertField('text0', 'd') | ||
test.assertSelectorHasText('#texts', 'd,e,ffff') | ||
}) | ||
.run(function () { | ||
test.done() | ||
}) | ||
|
||
}) |