Skip to content

Commit 4b20ad6

Browse files
committed
refactor v-repeat alias/meta logic
1 parent 418bc43 commit 4b20ad6

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/directives/repeat.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,20 +268,22 @@ module.exports = {
268268
*/
269269

270270
build: function (data, index, needCache) {
271-
var original = data
272271
var meta = { $index: index }
273272
if (this.converted) {
274-
meta.$key = original.$key
273+
meta.$key = data.$key
275274
}
276275
var raw = this.converted ? data.$value : data
277276
var alias = this.arg
278-
var hasAlias = !isObject(raw) || !isPlainObject(data) || alias
279-
// wrap the raw data with alias
280-
data = hasAlias ? {} : raw
281277
if (alias) {
278+
data = {}
282279
data[alias] = raw
283-
} else if (hasAlias) {
280+
} else if (!isPlainObject(raw)) {
281+
// non-object values
282+
data = {}
284283
meta.$value = raw
284+
} else {
285+
// default
286+
data = raw
285287
}
286288
// resolve constructor
287289
var Ctor = this.Ctor || this.resolveCtor(data, meta)

test/unit/specs/directives/repeat_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ if (_.inBrowser) {
256256
}
257257
},
258258
template: '<div v-repeat="listHash">{{$key}}' +
259-
'<p v-repeat="$data">{{a}}</p>' +
259+
'<p v-repeat="$value">{{a}}</p>' +
260260
'</div>'
261261
})
262262
function output(key){

0 commit comments

Comments
 (0)