Skip to content

Commit 12c82fe

Browse files
committed
fix v-repeat with v-component (fix vuejs#1004)
1 parent 6204145 commit 12c82fe

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

src/compiler/compile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ function compileElement (el, options) {
247247
}
248248
// check component
249249
if (!linkFn) {
250-
linkFn = checkComponent(el, options, hasAttrs)
250+
linkFn = checkComponent(el, options)
251251
}
252252
// normal directives
253253
if (!linkFn && hasAttrs) {

src/util/misc.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,11 @@ function formatValue (val) {
7474
*
7575
* @param {Element} el
7676
* @param {Object} options
77-
* @param {Boolean} hasAttrs
7877
* @return {String|undefined}
7978
*/
8079

8180
exports.commonTagRE = /^(div|p|span|img|a|br|ul|ol|li|h1|h2|h3|h4|h5|code|pre)$/
82-
exports.checkComponent = function (el, options, hasAttrs) {
81+
exports.checkComponent = function (el, options) {
8382
var tag = el.tagName.toLowerCase()
8483
if (tag === 'component') {
8584
// dynamic syntax
@@ -91,10 +90,9 @@ exports.checkComponent = function (el, options, hasAttrs) {
9190
_.resolveAsset(options, 'components', tag)
9291
) {
9392
return tag
94-
} else if (
95-
hasAttrs &&
96-
(tag = _.attr(el, 'component'))
97-
) {
93+
/* eslint-disable no-cond-assign */
94+
} else if (tag = _.attr(el, 'component')) {
95+
/* eslint-enable no-cond-assign */
9896
return tag
9997
}
10098
}

test/unit/specs/directives/repeat_spec.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,23 @@ if (_.inBrowser) {
155155
assertMutations(vm, el, done)
156156
})
157157

158+
it('v-component', function (done) {
159+
var vm = new Vue({
160+
el: el,
161+
data: {
162+
items: [{a: 1}, {a: 2}]
163+
},
164+
template: '<p v-repeat="items" v-component="test"></p>',
165+
components: {
166+
test: {
167+
template: '<div>{{$index}} {{a}}</div>',
168+
replace: true
169+
}
170+
}
171+
})
172+
assertMutations(vm, el, done)
173+
})
174+
158175
it('component with inline-template', function (done) {
159176
var vm = new Vue({
160177
el: el,
@@ -547,12 +564,9 @@ if (_.inBrowser) {
547564
var obj = {}
548565
new Vue({
549566
el: el,
550-
template: '<div v-repeat="items" v-component="test"></div>',
567+
template: '<div v-repeat="items"></div>',
551568
data: {
552569
items: [obj, obj]
553-
},
554-
components: {
555-
test: {}
556570
}
557571
})
558572
expect(hasWarned(_, 'Duplicate objects')).toBe(true)
@@ -561,12 +575,9 @@ if (_.inBrowser) {
561575
it('warn duplicate trackby id', function () {
562576
new Vue({
563577
el: el,
564-
template: '<div v-repeat="items" v-component="test" track-by="id"></div>',
578+
template: '<div v-repeat="items" track-by="id"></div>',
565579
data: {
566580
items: [{id: 1}, {id: 1}]
567-
},
568-
components: {
569-
test: {}
570581
}
571582
})
572583
expect(hasWarned(_, 'Duplicate track-by key')).toBe(true)
@@ -602,12 +613,9 @@ if (_.inBrowser) {
602613
it('teardown', function () {
603614
var vm = new Vue({
604615
el: el,
605-
template: '<div v-repeat="items" v-component="test"></div>',
616+
template: '<div v-repeat="items"></div>',
606617
data: {
607618
items: [{a: 1}, {a: 2}]
608-
},
609-
components: {
610-
test: {}
611619
}
612620
})
613621
vm._directives[0].unbind()

0 commit comments

Comments
 (0)