Skip to content

Commit 659593f

Browse files
committed
dataAttributes options (#125)
1 parent 3693ca7 commit 659593f

File tree

4 files changed

+26
-30
lines changed

4 files changed

+26
-30
lines changed

src/compiler.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ function Compiler (vm, options) {
8989
}
9090
}
9191

92+
// copy paramAttributes
93+
if (options.paramAttributes) {
94+
options.paramAttributes.forEach(function (attr) {
95+
var val = el.getAttribute(attr)
96+
vm[attr] = isNaN(val) ? val : Number(val)
97+
})
98+
}
99+
92100
// beforeCompile hook
93101
compiler.execHook('created')
94102

src/directives/index.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
var utils = require('../utils'),
22
config = require('../config'),
3-
transition = require('../transition'),
4-
NumberRE = /^[\d\.]+$/,
5-
CommaRE = /\\,/g
3+
transition = require('../transition')
64

75
module.exports = {
86

@@ -56,18 +54,6 @@ module.exports = {
5654
el.removeAttribute(config.prefix + '-cloak')
5755
})
5856
}
59-
},
60-
61-
data: {
62-
bind: function () {
63-
var val = this.key
64-
this.vm.$set(
65-
this.arg,
66-
NumberRE.test(val)
67-
? +val
68-
: val.replace(CommaRE, ',')
69-
)
70-
}
7157
}
7258

7359
}

test/unit/specs/api.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,23 @@ describe('UNIT: API', function () {
602602

603603
})
604604

605+
describe('paramAttributes', function () {
606+
607+
it('should copy listed attributes into data and parse Numbers', function () {
608+
var Test = Vue.extend({
609+
template: '<div a="1" b="hello"></div>',
610+
replace: true,
611+
paramAttributes: ['a', 'b']
612+
})
613+
var v = new Test()
614+
assert.strictEqual(v.a, 1)
615+
assert.strictEqual(v.$data.a, 1)
616+
assert.strictEqual(v.b, 'hello')
617+
assert.strictEqual(v.$data.b, 'hello')
618+
})
619+
620+
})
621+
605622
describe('directives', function () {
606623

607624
it('should allow the VM to use private directives', function (done) {

test/unit/specs/directives.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -844,21 +844,6 @@ describe('UNIT: Directives', function () {
844844

845845
})
846846

847-
describe('data', function () {
848-
849-
it('should set data on the child VM', function () {
850-
var v = new Vue({
851-
template: '<div v-component="test" v-ref="test" v-data="a:1,b:hi"></div>',
852-
components: {
853-
test: Vue
854-
}
855-
})
856-
assert.strictEqual(v.$.test.a, 1)
857-
assert.strictEqual(v.$.test.b, 'hi')
858-
})
859-
860-
})
861-
862847
})
863848

864849
function mockDirective (dirName, tag, type) {

0 commit comments

Comments
 (0)