Просмотр исходного кода

allow to initialize value attribute to 0 (#3334)

katashin 10 лет назад
Родитель
Сommit
bbc07afd15

+ 3 - 2
src/platforms/web/runtime/modules/dom-props.js

@@ -22,8 +22,9 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
       // non-string values will be stringified
       elm._value = cur
       // avoid resetting cursor position when value is the same
-      if (elm.value != cur) { // eslint-disable-line
-        elm.value = cur
+      const strCur = cur == null ? '' : String(cur)
+      if (elm.value !== strCur) {
+        elm.value = strCur
       }
     } else {
       elm[key] = cur

+ 6 - 0
test/unit/modules/vdom/modules/props.spec.js

@@ -23,4 +23,10 @@ describe('vdom domProps module', () => {
     const elm = patch(vnode1, vnode2)
     expect(elm.src).toBeUndefined()
   })
+
+  it('should initialize the elements value to zero', () => {
+    const vnode = new VNode('input', { domProps: { value: 0 }})
+    const elm = patch(null, vnode)
+    expect(elm.value).toBe('0')
+  })
 })