This time I bring you Vue 2.0 internal instructions. What are the precautions when using Vue 2.0 internal instructions. Here are practical cases, let’s take a look.
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, and the state can also be said to be data; and its componentization concept is the same as React, that is, "everything is a component, and the componentization idea is convenient for Modularization## The development of # is a major trend in the front-end field.
2. Internal instructions2-1.v-if v-else v-show: The first two are generally used together, and the effect of v-show is similar to v-if.
Examples are as follows:<body> <p id="app"> <p v-if="flag">if</p> <p v-else>else</p> <p v-show="flag">show</p> </p> </body> <script> var vm= new Vue({ el:"#app", data:{ flag:true } }); </script>
display
attribute is set to its default attribute, otherwise, it is set to none)Examples are as follows:
<body> <p id="app"> <ol> <li v-for="b in b">{{b}}</li> </ol> </p> </body> <script> var vm= new Vue({ el:"#app", data:{ b:['a','b','c',1,2] } }); </script>
array
b one-to-one. v-for is somewhat similar to for in loopString) command<body>
<p id="app">
<p v-text="msgText"></p>
<p v-html="msgHtml"></p>
</p>
</body>
<script>
var vm= new Vue({
el:"#app",
data:{
msgText:"China",
msgHtml:"<span>中国</span>"
}
});
</script>
2-4 v-on binding event listener
Examples are as follows:
<body> <p id="app"> <button v-on:click="Hi()">Button</button> </p> </body> <script> var vm= new Vue({ el:"#app", methods:{ Hi:function(){ alert("Hello World!") } } }); </script>
2-5 v-bind command
Examples are as follows:
<body> <p id="app"> <a v-bind:style="{color:'red'}" :src="message">{{message}}</a> </p> </body> <script> var vm = new Vue({ el: "#app", data: { message: "前端工程师" } }); </script>
html tag
. Its abbreviation is v-bind:——>:2-6 v-model two-way data binding instructions
Examples are as follows:
<body> <p id="app"> <p>{{message}}</p> <input type="text" v-model="message"> </p> </body> <script> var vm = new Vue({ el: "#app", data: { message: "前端工程师" } }); </script>
Examples are as follows:
<body> <p id="app"> <p>{{message}}</p> <p v-pre>{{message}}</p> </p> </body> <script> var vm = new Vue({ el: "#app", data: { message: "前端工程师" } }); </script>
2-8 v-cloak command
The function of the v-cloak instruction is to execute it after the DOM tree is constructed and the page is rendered, and it needs to be used together with css
2-9 v-once command
The v-once directive only works when the DOM tree is rendered for the first time.
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website! Recommended reading:The above is the detailed content of Vue 2.0 internal directives. For more information, please follow other related articles on the PHP Chinese website!