当前位置:网站首页>6. common instructions (upper) v-cloak, v-once, v-pre
6. common instructions (upper) v-cloak, v-once, v-pre
2022-06-25 23:53:00 【Rice bowl on the other side】
v-cloak
v-cloak The function of instruction is vue End of association after sample rendering
The double brace interpolation syntax will display the precompiled text when encountering network delay
<body>
<div id="app">
<p>{
{a}}</p>
</div>
<script src="vue.js"></script>
<script> var vue=new Vue({
el:"#app", data:{
a:" I am the instruction of rendering v-cloak" }, }) </script>
</body>
Here it is , We can use v-cloak combination CSS Solve the problem of double brace rendering
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style> [v-cloak]{
display: none; } </style>
</head>
<body>
<div id="app">
<p v-cloak>{
{a}}</p>
</div>
<script src="vue.js"></script>
<script> var vue=new Vue({
el:"#app", data:{
a:" I am the instruction of rendering v-cloak" }, }) </script>
</body>
[v-cloak]css The selector selects html In the structure v-cloak Properties of , The element setting with this attribute display by none, because v-cloak This attribute is in vue After the instance of is loaded, the results are associated , So you need the hidden state of this element , The result is , Or blank , Or display the compiled text .
v-once
v-once The function of is to render the corresponding element only once , Data updates do not cause view updates , The goal is to optimize the page .
<body>
<div id="app">
<h2 v-once>{
{a}}</h2>
<button @click="add"> I'll add one </button>
<button @click="minus"> Point I minus one </button>
</div>
<script src="vue.js"></script>
<script> var vue=new Vue({
el:"#app", data:{
a:100 }, methods:{
add(){
this.a++ console.log(this.a) }, minus(){
this.a-- console.log(this.a) } } }) </script>
</body>
Usage scenarios usually have no dynamic element content , For example, some articles , Some fixed titles
v-pre
v-pre The function of attributes : Skip the compilation of this element , Directly display the text inside the element , The function is to skip a large number of nodes without instructions .
<h2 v-pre>{
{a}}</h2>

What the browser shows is that it has not been compiled h2 The text content in the element ,v-pre The advantage of property is to optimize the loading performance of the page
边栏推荐
猜你喜欢
随机推荐
mysql
CXF
Summary of c++ references and pointers
Uniapp -- framework arrangement and analysis summary
Let's talk about string today
Jenkins 发布PHP项目代码
[转载]RSLOGIX 5000实例教程
php中使用google protobuf协议环境配置
对伪类的理解
Problems encountered in Doris operation and maintenance
Leetcode 513. 找树左下角的值
中序线索二叉树
Talk about singleton mode!
使用百度地图API在地图中设置一个覆盖物(InfoWindow),可自定义窗口内容
proxy
Megacli常用命令整理
static关键字详解
DPVS-FullNAT模式keepalived篇
51 single chip microcomputer, some registers, some knowledge points
记录一下刷LeetCode瞬间有思路的一道简单题——剑指 Offer 09. 用两个栈实现队列









![寻找翻转数组的最小值[抽象二分]](/img/b9/1e0c6196e6dc51ae2c48f6c5e83289.png)