Jelajahi Sumber

fix toString

Evan You 10 tahun lalu
induk
melakukan
403e2380b8
2 mengubah file dengan 8 tambahan dan 3 penghapusan
  1. 1 1
      src/compiler/parser/text-parser.js
  2. 7 2
      src/runtime/instance/render.js

+ 1 - 1
src/compiler/parser/text-parser.js

@@ -15,7 +15,7 @@ export function parseText (text) {
     }
     // tag token
     const exp = match[1].trim()
-    tokens.push(`((${exp})==null?'':__s__(${exp}))`)
+    tokens.push(`__s__(${exp})`)
     lastIndex = index + match[0].length
   }
   if (lastIndex < text.length) {

+ 7 - 2
src/runtime/instance/render.js

@@ -21,13 +21,18 @@ export function renderMixin (Vue) {
   // shorthands used in render functions
   Vue.prototype.__h__ = createElement
 
+  // resolve directive
   Vue.prototype.__d__ = function (id) {
     return resolveAsset(this.$options, 'directives', id, true)
   }
 
+  // toString for mustaches
   Vue.prototype.__s__ = function (val) {
-    console.log(val)
-    return typeof val === 'string' ? val : JSON.stringify(val)
+    return val == null
+      ? ''
+      : typeof val === 'object'
+        ? JSON.stringify(val, null, 2)
+        : val
   }
 
   Vue.prototype._update = function (vnode) {