Skip to content

Commit 3f3b612

Browse files
committed
partial: fix dynamic partial scope issue (fix #1363)
1 parent ab2ff32 commit 3f3b612

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

src/api/data.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ exports.$delete = function (key) {
6464
* @param {Object} [options]
6565
* - {Boolean} deep
6666
* - {Boolean} immediate
67-
* - {Boolean} user
6867
* @return {Function} - unwatchFn
6968
*/
7069

@@ -77,7 +76,6 @@ exports.$watch = function (expOrFn, cb, options) {
7776
}
7877
var watcher = new Watcher(vm, expOrFn, cb, {
7978
deep: options && options.deep,
80-
user: !options || options.user !== false,
8179
filters: parsed && parsed.filters
8280
})
8381
if (options && options.immediate) {

src/directives/element/partial.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var _ = require('../../util')
22
var FragmentFactory = require('../../fragment/factory')
33
var vIf = require('../public/if')
4+
var Watcher = require('../../watcher')
45

56
module.exports = {
67

@@ -24,14 +25,16 @@ module.exports = {
2425

2526
setupDynamic: function (exp) {
2627
var self = this
27-
this.unwatch = this.vm.$watch(exp, function (value) {
28+
var onNameChange = function (value) {
2829
vIf.remove.call(self)
29-
self.insert(value)
30-
}, {
31-
immediate: true,
32-
user: false,
30+
if (value) {
31+
self.insert(value)
32+
}
33+
}
34+
this.nameWatcher = new Watcher(this.vm, exp, onNameChange, {
3335
scope: this._scope
3436
})
37+
onNameChange(this.nameWatcher.value)
3538
},
3639

3740
insert: function (id) {
@@ -46,7 +49,11 @@ module.exports = {
4649
},
4750

4851
unbind: function () {
49-
if (this.frag) this.frag.destroy()
50-
if (this.unwatch) this.unwatch()
52+
if (this.frag) {
53+
this.frag.destroy()
54+
}
55+
if (this.nameWatcher) {
56+
this.nameWatcher.teardown()
57+
}
5158
}
5259
}

test/unit/specs/directives/element/partial_spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ describe('Partial', function () {
4848
})
4949
})
5050

51+
it('dynamic inside v-for', function () {
52+
new Vue({
53+
el: el,
54+
template: '<div v-for="id in list"><partial v-bind:name="\'test-\' + id"></partial></div>',
55+
data: {
56+
list: ['a', 'b']
57+
},
58+
partials: {
59+
'test-a': 'a {{id}}',
60+
'test-b': 'b {{id}}'
61+
}
62+
})
63+
expect(el.textContent).toBe('a ab b')
64+
})
65+
5166
it('caching', function () {
5267
var calls = 0
5368
var compile = compiler.compile

0 commit comments

Comments
 (0)