All Products
Search
Document Center

Mobile Platform as a Service:Logical rendering

Last Updated:Apr 24, 2023

This article describes the types of logical rendering and the corresponding instructions.

Conditional 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-show result is true, it is equivalent to adding a display: flex to the CSS style of the node.

  • If the v-show result is false, it is equivalent to adding a display: none to 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-if to act as v-if "else-if blocks" that can be used consecutively.

  • You can use v-else to act as "else blocks" for v-if.

<div class="div" v-if="exist(a)">
  ...
</div>
<div class="div" v-else-if="exist(b)">
  ...
</div>
<div class="div" v-else>
  ...
</div>
Important
  • The v-else-if must immediately follow the v-if block or it will not be recognized.

  • The v-else must immediately follow the v-if or v-else-if block or it will not be recognized.

  • v-if cannot 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>
Note

  • v-for instructions do not support nested use, that is, v-for can no longer use v-for for 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/number data.

  • v-for cannot be written on the root node of a template.

Examples

Click here detailLogicalRender.zip for the complete sample code.