Evan You 12 лет назад
Родитель
Сommit
c599bed93d
3 измененных файлов с 19 добавлено и 5 удалено
  1. 3 2
      examples/todomvc/index.html
  2. 6 3
      src/compiler.js
  3. 10 0
      src/directives/index.js

+ 3 - 2
examples/todomvc/index.html

@@ -4,6 +4,7 @@
         <title>Todo</title>
         <title>Todo</title>
         <meta charset="utf-8">
         <meta charset="utf-8">
         <link rel="stylesheet" type="text/css" href="bower_components/todomvc-common/base.css">
         <link rel="stylesheet" type="text/css" href="bower_components/todomvc-common/base.css">
+        <style> [v-cloak] { display: none; } </style>
     </head>
     </head>
     <body>
     <body>
         <section id="todoapp">
         <section id="todoapp">
@@ -18,7 +19,7 @@
                     v-on="keyup:addTodo | key enter"
                     v-on="keyup:addTodo | key enter"
                 >
                 >
             </header>
             </header>
-            <section id="main" v-show="todos.length">
+            <section id="main" v-show="todos.length" v-cloak>
                 <input
                 <input
                     id="toggle-all"
                     id="toggle-all"
                     type="checkbox"
                     type="checkbox"
@@ -58,7 +59,7 @@
                     </li>
                     </li>
                 </ul>
                 </ul>
             </section>
             </section>
-            <footer id="footer" v-show="todos.length">
+            <footer id="footer" v-show="todos.length" v-cloak>
                 <span id="todo-count">
                 <span id="todo-count">
                     <strong v-text="remaining"></strong> {{remaining | pluralize item}} left
                     <strong v-text="remaining"></strong> {{remaining | pluralize item}} left
                 </span>
                 </span>

+ 6 - 3
src/compiler.js

@@ -330,7 +330,7 @@ CompilerProto.compileNode = function (node) {
         prefix = config.prefix + '-'
         prefix = config.prefix + '-'
     // parse if has attributes
     // parse if has attributes
     if (attrs && attrs.length) {
     if (attrs && attrs.length) {
-        var attr, isDirective, exps, exp, directive
+        var attr, isDirective, exps, exp, directive, dirname
         // loop through all attributes
         // loop through all attributes
         i = attrs.length
         i = attrs.length
         while (i--) {
         while (i--) {
@@ -346,7 +346,8 @@ CompilerProto.compileNode = function (node) {
                 j = exps.length
                 j = exps.length
                 while (j--) {
                 while (j--) {
                     exp = exps[j]
                     exp = exps[j]
-                    directive = Directive.parse(attr.name.slice(prefix.length), exp, this, node)
+                    dirname = attr.name.slice(prefix.length)
+                    directive = Directive.parse(dirname, exp, this, node)
                     if (directive) {
                     if (directive) {
                         this.bindDirective(directive)
                         this.bindDirective(directive)
                     }
                     }
@@ -362,7 +363,9 @@ CompilerProto.compileNode = function (node) {
                 }
                 }
             }
             }
 
 
-            if (isDirective) node.removeAttribute(attr.name)
+            if (isDirective && dirname !== 'cloak') {
+                node.removeAttribute(attr.name)
+            }
         }
         }
     }
     }
     // recursively compile childNodes
     // recursively compile childNodes

+ 10 - 0
src/directives/index.js

@@ -1,4 +1,5 @@
 var utils      = require('../utils'),
 var utils      = require('../utils'),
+    config     = require('../config'),
     transition = require('../transition')
     transition = require('../transition')
 
 
 module.exports = {
 module.exports = {
@@ -44,6 +45,15 @@ module.exports = {
                 this.lastVal = value
                 this.lastVal = value
             }
             }
         }
         }
+    },
+
+    cloak: {
+        bind: function () {
+            var el = this.el
+            this.compiler.observer.once('hook:ready', function () {
+                el.removeAttribute(config.prefix + '-cloak')                
+            })   
+        }
     }
     }
 
 
 }
 }