Skip to content

Commit 76c4d47

Browse files
committed
fix #458 dynamic component using meta properties
1 parent d4578da commit 76c4d47

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

src/directives/repeat.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ module.exports = {
277277
meta.$value = raw
278278
}
279279
// resolve constructor
280-
var Ctor = this.Ctor || this.resolveCtor(data)
280+
var Ctor = this.Ctor || this.resolveCtor(data, meta)
281281
var vm = this.vm.$addChild({
282282
el: this.template.cloneNode(true),
283283
_linker: this._linker,
@@ -296,16 +296,22 @@ module.exports = {
296296
* components depending on instance data.
297297
*
298298
* @param {Object} data
299+
* @param {Object} meta
299300
* @return {Function}
300301
*/
301302

302-
resolveCtor: function (data) {
303+
resolveCtor: function (data, meta) {
304+
// create a temporary context object and copy data
305+
// and meta properties onto it.
306+
// use _.define to avoid accidentally overwriting scope
307+
// properties.
303308
var context = Object.create(this.vm)
304309
for (var key in data) {
305-
// use _.define to avoid accidentally
306-
// overwriting scope properties
307310
_.define(context, key, data[key])
308311
}
312+
for (var key in meta) {
313+
_.define(context, key, meta[key])
314+
}
309315
var id = this.ctorGetter.call(context, context)
310316
var Ctor = this.vm.$options.components[id]
311317
_.assertAsset(Ctor, 'component', id)

test/unit/specs/directives/repeat_spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,26 @@ if (_.inBrowser) {
171171
}
172172
})
173173
expect(el.innerHTML).toBe('<div>AAA</div><div>BBB</div><div>CCC</div><!--v-repeat-->')
174+
// #458 meta properties
175+
var vm = new Vue({
176+
el: el,
177+
template: '<div v-repeat="list" v-component="view-{{$value}}"></div>',
178+
data: {
179+
list: ['a', 'b', 'c']
180+
},
181+
components: {
182+
'view-a': {
183+
template: 'AAA'
184+
},
185+
'view-b': {
186+
template: 'BBB'
187+
},
188+
'view-c': {
189+
template: 'CCC'
190+
}
191+
}
192+
})
193+
expect(el.innerHTML).toBe('<div>AAA</div><div>BBB</div><div>CCC</div><!--v-repeat-->')
174194
})
175195

176196
it('block repeat', function () {

0 commit comments

Comments
 (0)