Home > Article > Web Front-end > What are the internal directives in Vue 2.0
1.Vue.js introduction
There are currently three mainstream front-end frameworks: Angular, React, and Vue. Due to the license controversy of React some time ago, the popularity of Vue has been rising. In addition, Vue’s friendly API documentation is a major feature. Vue.js is a very lightweight tool, more like a js library than an MVVM framework. Vue.js features responsive programming and componentization. Reactive programming means keeping the state and the view synchronized. The state can also be said to be data; and its componentization concept is the same as React, that is, "everything is a component. The componentization idea is convenient for modular development and is the front-end A major trend in the field
2. Internal instructions
##2-1.v-if v-else v-show: The first two. are generally used together, the effect of v-show is similar to v-if
The example is as follows:##
<body> <div id="app"> <p v-if="flag">if</p> <p v-else>else</p> <p v-show="flag">show</p> </div> </body> <script> var vm= new Vue({ el:"#app", data:{ flag:true } }); </script>
The example is as follows:
<body> <div id="app"> <ol> <li v-for="b in b">{{b}}</li> </ol> </div> </body> <script> var vm= new Vue({ el:"#app", data:{ b:['a','b','c',1,2] } }); </script>
<body> <div id="app"> <p v-text="msgText"></p> <p v-html="msgHtml"></p> </div> </body> <script> var vm= new Vue({ el:"#app", data:{ msgText:"China", msgHtml:"<span>中国</span>" } }); </script>
is as follows:
<body> <div id="app"> <button v-on:click="Hi()">Button</button> </div> </body> <script> var vm= new Vue({ el:"#app", methods:{ Hi:function(){ alert("Hello World!") } } }); </script>
##2-5 v-bind command
The example is as follows:
##
<body> <div id="app"> <a v-bind:style="{color:'red'}" :src="message">{{message}}</a> </div> </body> <script> var vm = new Vue({ el: "#app", data: { message: "前端工程师" } }); </script>The effect is that the a tag displays red, and its src attribute is vm.message. The v-bind instruction is mainly used to set the attributes of the html tag. The abbreviated form is v-bind:——>:
The example is as follows:<body>
<div id="app">
<p>{{message}}</p>
<p v-pre>{{message}}</p>
</div>
</body>
<script>
var vm = new Vue({
el: "#app",
data: {
message: "前端工程师"
}
});
</script>
When the input value changes, the content contained in the p tag will also change and remain consistent with the former.
The example is as follows:<body>
<div id="app">
<p>{{message}}</p>
<p v-pre>{{message}}</p>
</div>
</body>
<script>
var vm = new Vue({
el: "#app",
data: {
message: "前端工程师"
}
});
</script>
The first p tag outputs "front-end engineer", while the second The p tag will skip vue compilation and output the original value, namely {{message}}.
The function of the v-cloak instruction is to execute it after the DOM tree is built and the rendering of the page is completed, and it needs to be consistent with css Use together
2-9 v-once directiveThe v-once directive only works when the DOM tree is rendered for the first time.
The above is the detailed content of What are the internal directives in Vue 2.0. For more information, please follow other related articles on the PHP Chinese website!