Explorar el Código

[1.x]Empty string should not be casted to 0 (fix #3577, #3541) (#4118)

* 	empty string should not be casted to 0. Backport it from vue2

* trim whitespace

* fix coding style

* fix coding style
chengchao hace 9 años
padre
commit
12ecce5b4d
Se han modificado 1 ficheros con 5 adiciones y 6 borrados
  1. 5 6
      src/util/lang.js

+ 5 - 6
src/util/lang.js

@@ -126,14 +126,13 @@ export function _toString (value) {
  */
 
 export function toNumber (value) {
-  if (typeof value !== 'string') {
+  if (typeof value !== 'string' || value.trim() === '') {
     return value
-  } else {
-    var parsed = Number(value)
-    return isNaN(parsed)
-      ? value
-      : parsed
   }
+  var parsed = Number(value)
+  return isNaN(parsed)
+    ? value
+    : parsed
 }
 
 /**