Skip to content

Commit c599bed

Browse files
author
Evan You
committed
add v-cloak
1 parent 23cdb4b commit c599bed

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

examples/todomvc/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<title>Todo</title>
55
<meta charset="utf-8">
66
<link rel="stylesheet" type="text/css" href="bower_components/todomvc-common/base.css">
7+
<style> [v-cloak] { display: none; } </style>
78
</head>
89
<body>
910
<section id="todoapp">
@@ -18,7 +19,7 @@ <h1>todos</h1>
1819
v-on="keyup:addTodo | key enter"
1920
>
2021
</header>
21-
<section id="main" v-show="todos.length">
22+
<section id="main" v-show="todos.length" v-cloak>
2223
<input
2324
id="toggle-all"
2425
type="checkbox"
@@ -58,7 +59,7 @@ <h1>todos</h1>
5859
</li>
5960
</ul>
6061
</section>
61-
<footer id="footer" v-show="todos.length">
62+
<footer id="footer" v-show="todos.length" v-cloak>
6263
<span id="todo-count">
6364
<strong v-text="remaining"></strong> {{remaining | pluralize item}} left
6465
</span>

src/compiler.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ CompilerProto.compileNode = function (node) {
330330
prefix = config.prefix + '-'
331331
// parse if has attributes
332332
if (attrs && attrs.length) {
333-
var attr, isDirective, exps, exp, directive
333+
var attr, isDirective, exps, exp, directive, dirname
334334
// loop through all attributes
335335
i = attrs.length
336336
while (i--) {
@@ -346,7 +346,8 @@ CompilerProto.compileNode = function (node) {
346346
j = exps.length
347347
while (j--) {
348348
exp = exps[j]
349-
directive = Directive.parse(attr.name.slice(prefix.length), exp, this, node)
349+
dirname = attr.name.slice(prefix.length)
350+
directive = Directive.parse(dirname, exp, this, node)
350351
if (directive) {
351352
this.bindDirective(directive)
352353
}
@@ -362,7 +363,9 @@ CompilerProto.compileNode = function (node) {
362363
}
363364
}
364365

365-
if (isDirective) node.removeAttribute(attr.name)
366+
if (isDirective && dirname !== 'cloak') {
367+
node.removeAttribute(attr.name)
368+
}
366369
}
367370
}
368371
// recursively compile childNodes

src/directives/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var utils = require('../utils'),
2+
config = require('../config'),
23
transition = require('../transition')
34

45
module.exports = {
@@ -44,6 +45,15 @@ module.exports = {
4445
this.lastVal = value
4546
}
4647
}
48+
},
49+
50+
cloak: {
51+
bind: function () {
52+
var el = this.el
53+
this.compiler.observer.once('hook:ready', function () {
54+
el.removeAttribute(config.prefix + '-cloak')
55+
})
56+
}
4757
}
4858

4959
}

0 commit comments

Comments
 (0)