Skip to content

Commit a49e561

Browse files
author
Evan You
committed
fix vuejs#310 v-style fails with number values
1 parent 5016e0b commit a49e561

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/directives/style.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ module.exports = {
1919
update: function (value) {
2020
var prop = this.prop,
2121
isImportant
22+
/* jshint eqeqeq: true */
23+
// cast possible numbers/booleans into strings
24+
if (value != null) value += ''
2225
if (prop) {
23-
if (value){
26+
if (value) {
2427
isImportant = value.slice(-10) === '!important'
2528
? 'important'
2629
: ''

test/unit/specs/directives.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,14 @@ describe('Directives', function () {
715715
assert.strictEqual(d.el.style.color, 'rgb(255, 255, 255)')
716716
})
717717

718+
it('should work with numbers', function () {
719+
var d = mockDirective('style')
720+
d.arg = 'line-height'
721+
d.bind()
722+
d.update(0)
723+
assert.strictEqual(d.el.style.lineHeight, '0')
724+
})
725+
718726
})
719727

720728
describe('cloak', function () {

0 commit comments

Comments
 (0)