This article describes the types of logical rendering and the corresponding instructions.
Condition rendering
v-show
v-show instructions are used to conditionally render the content of a node. The node is rendered regardless of whether the result of the v-show instruction is true or false.
If the
v-showresult istrue, it is equivalent to adding adisplay: flexto the CSS style of the node.If the
v-showresult isfalse, it is equivalent to adding adisplay: noneto the CSS style of the node.
<div class="div" v-show="exist(exist4)"></div>v-if
v-if instructions are used to conditionally render a piece of content. This piece of content will only be rendered when the expression of the directive returns a true.
You can use
v-else-ifto act asv-if"else-if blocks" that can be used consecutively.You can use
v-elseto act as "else blocks" forv-if.
<div class="div" v-if="exist(a)">
...
</div>
<div class="div" v-else-if="exist(b)">
...
</div>
<div class="div" v-else>
...
</div>The
v-else-ifmust immediately follow thev-ifblock or it will not be recognized.The
v-elsemust immediately follow thev-iforv-else-ifblock or it will not be recognized.v-ifcannot be written on the root node of a template.
List rendering
vfor
v-for instructions may render a set of data based on an array /number/ object. Currently, six methods are supported:
v-for="index in 10"
v-for="index in number"
v-for="item in array"
v-for="(item,index) in array"
v-for="item in object"
v-for="(item,key) in object"
<div class="vforStyle" v-for="(value,index) in obj">
<text class="content">{{index + value}}</text>
</div>v-forinstructions do not support nested use, that is,v-forcan no longer usev-forfor rendering.When rendering data based on objects, the order in which objects are displayed is not controllable. To display in a determined order, iterate through the
array/numberdata.v-forcannot be written on the root node of a template.
Example code
Click here detailLogicalRender.zip for the complete sample code.