v-cloak
We already know that two-way binding method is as follows:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>v-cloak</title>
</head>
<div id="app">
<p>{{msg}}</p>
</div>
<body>
<script src="lib/vue.js"></script>
<script>
var vm = new Vue({
el: '#app',
data: {
msg: '123'
}
})
</script>
</body>
</html>
Effect:
adjust the speed of the network:
browser f12, find Network, into Slow 3G, refresh the page
display as follows:
when a relatively slow speed, we can see the interpolation expression, this time the v-cloak played:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>v-cloak</title>
<style>
/*凡是使用了v-cloak指令的标签,都设置成隐藏*/
[v-cloak]{
display: none;
}
</style>
</head>
<div id="app">
<p v-cloak>{{msg}}</p>
</div>
<body>
<script src="lib/vue.js"></script>
<script>
var vm = new Vue({
el: '#app',
data: {
msg: '123'
}
})
</script>
</body>
</html>
This time to refresh the page:
When the request is completed, will show the value:
it is v-cloak
possible to solve the problem of interpolation expressions flicker
v-text
v-text
Use:
<p v-text="msg"></p>
v-text
Does not require any configuration, direct expression flicker problems interpolation does not exist.
Consider the following scenario:
<p v-cloak>hello {{msg}}</p> <!--输出:hello 123-->
<p v-text="msg">hello</p> <!--输出:123 ("123"会将"hello"替换掉)-->
In other words, if you do not just want to output the string, the string would also like stitching around a number of other characters when using v-cloak
.
If you want to output the string itself, use v-text
.
v-html
v-html
Will render the content as html, using the following method:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>v-html</title>
</head>
<div id="app">
<p v-html="msg"></p>
</div>
<body>
<script src="lib/vue.js"></script>
<script>
var vm = new Vue({
el: '#app',
data: {
msg: '<h1>我是一个h1标签</h1>'
}
})
</script>
</body>
</html>
Msg contents page will render as html: