Skip to content

Commit fd69bcc

Browse files
committed
support interpolations in directive params (fix #1083)
1 parent 99f3774 commit fd69bcc

File tree

4 files changed

+23
-28
lines changed

4 files changed

+23
-28
lines changed

src/directive.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ p._checkParam = function (name) {
166166
var param = this.el.getAttribute(name)
167167
if (param !== null) {
168168
this.el.removeAttribute(name)
169+
param = this.vm.$interpolate(param)
169170
}
170171
return param
171172
}

src/directives/component.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var _ = require('../util')
2+
var config = require('../config')
23
var templateParser = require('../parsers/template')
34

45
module.exports = {
@@ -29,7 +30,7 @@ module.exports = {
2930
// wait for event before insertion
3031
this.readyEvent = this._checkParam('wait-for')
3132
// check ref
32-
this.refID = _.attr(this.el, 'ref')
33+
this.refID = this._checkParam(config.prefix + 'ref')
3334
if (this.keepAlive) {
3435
this.cache = {}
3536
}

src/directives/repeat.js

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var _ = require('../util')
2+
var config = require('../config')
23
var isObject = _.isObject
34
var isPlainObject = _.isPlainObject
45
var textParser = require('../parsers/text')
@@ -28,29 +29,37 @@ module.exports = {
2829
}
2930
// uid as a cache identifier
3031
this.id = '__v_repeat_' + (++uid)
32+
3133
// setup anchor nodes
3234
this.start = _.createAnchor('v-repeat-start')
3335
this.end = _.createAnchor('v-repeat-end')
3436
_.replace(this.el, this.end)
3537
_.before(this.start, this.end)
38+
3639
// check if this is a block repeat
3740
this.template = _.isTemplate(this.el)
3841
? templateParser.parse(this.el, true)
3942
: this.el
40-
// check other directives that need to be handled
41-
// at v-repeat level
42-
this.checkIf()
43-
this.checkRef()
44-
this.checkComponent()
43+
4544
// check for trackby param
46-
this.idKey =
47-
this._checkParam('track-by') ||
48-
this._checkParam('trackby') // 0.11.0 compat
45+
this.idKey = this._checkParam('track-by')
4946
// check for transition stagger
5047
var stagger = +this._checkParam('stagger')
5148
this.enterStagger = +this._checkParam('enter-stagger') || stagger
5249
this.leaveStagger = +this._checkParam('leave-stagger') || stagger
50+
51+
// check for v-ref/v-el
52+
this.refID = this._checkParam(config.prefix + 'ref')
53+
this.elID = this._checkParam(config.prefix + 'el')
54+
55+
// check other directives that need to be handled
56+
// at v-repeat level
57+
this.checkIf()
58+
this.checkComponent()
59+
60+
// create cache object
5361
this.cache = Object.create(null)
62+
5463
// some helpful tips...
5564
/* istanbul ignore if */
5665
if (
@@ -78,21 +87,6 @@ module.exports = {
7887
}
7988
},
8089

81-
/**
82-
* Check if v-ref/ v-el is also present.
83-
*/
84-
85-
checkRef: function () {
86-
var refID = _.attr(this.el, 'ref')
87-
this.refID = refID
88-
? this.vm.$interpolate(refID)
89-
: null
90-
var elId = _.attr(this.el, 'el')
91-
this.elId = elId
92-
? this.vm.$interpolate(elId)
93-
: null
94-
},
95-
9690
/**
9791
* Check the component constructor to use for repeated
9892
* instances. If static we resolve it now, otherwise it
@@ -226,8 +220,8 @@ module.exports = {
226220
? toRefObject(this.vms)
227221
: this.vms
228222
}
229-
if (this.elId) {
230-
this.vm.$$[this.elId] = this.vms.map(function (vm) {
223+
if (this.elID) {
224+
this.vm.$$[this.elID] = this.vms.map(function (vm) {
231225
return vm.$el
232226
})
233227
}

src/element-directives/content.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222
return
2323
}
2424
var context = host._context
25-
var selector = this.el.getAttribute('select')
25+
var selector = this._checkParam('select')
2626
if (!selector) {
2727
// Default content
2828
var self = this
@@ -44,7 +44,6 @@ module.exports = {
4444
}
4545
} else {
4646
// select content
47-
selector = vm.$interpolate(selector)
4847
var nodes = raw.querySelectorAll(selector)
4948
if (nodes.length) {
5049
content = extractFragment(nodes, raw)

0 commit comments

Comments
 (0)