uni-app的坑还是挺多的,这是今天遇到的一个坑,话不多说,上代码:

<view v-if="condition1"> 1 </view>
<template v-else-if="condition2">
    <view> 2 </view>
</template>

上面的代码中,template中的内容即使条件为 true,也可能在真机上不会显示出来。

解决的办法就是不要混用,如果确实要用到 template,那就全部用 template:

<template v-if="condition1">
    <view> 1 </view>
</template>
<template v-else-if="condition2">
    <view> 2 </view>
</template>

标签: uni-app