关于条件渲染中wx:if使用的问题?

小程序 文章 2021-12-20 11:40 430 0 全屏看文

AI助手支持GPT4.0

关于条件渲染中wx:if使用的问题?About the use of wx:if in conditional rendering?

关于条件渲染中wx:if使用的问题?

在官方文档中有这个例子,最终显示结果为3。

<view wx:if="{{length > 5}}"> 1 </view><view wx:elif="{{length > 2}}"> 2 </view><view wx:else> 3 </view>

我自己写成这样:

<view wx:if="{{length > 5}}"> 10 </view>

<view wx:elif="{{length > 2}}"> 4 </view>

<view wx:else> 3 </view>

我觉得结果应该显示为:10 4 3,但是结果还是显示3。这是什么原因啊?

第一条件10满足大于5的要求,

第二个条件4满足大于2小于等于5的要求

第三个条件满足小于等于5的要求。

三个要求都满足,为什么只显示最后一个条件3呢?


There is this example in the official document, and the final result is 3< View Wx: if = "{length > 5}}" > 1 < / View > < view Wx: elif = "{length > 2}}" > 2 < / View > < view Wx: else > 3 < / View > I wrote it myself: < view Wx: if = "{length > 5}}" > 10 < / View > < view Wx: elif = "{length > 2}}" > 4 < / View > < view Wx: else > 3 < / View > I think the result should be displayed as: 10 4 3, but the result still displays 3. What's the reason? The first condition 10 meets the requirements of greater than 5, the second condition 4 meets the requirements of greater than 2 and less than or equal to 5, and the third condition meets the requirements of less than or equal to 5. If all three requirements are met, why only the last condition 3 is displayed?

回答:

🍀 🌻  诚:
你的length是几
困难:

length不是你标签里的10 4 3.。。

这个双括号{{}}是看你js文件中data里对应的那个值,这里就是js的data中叫length的变量的值。

然后这三个条件渲染的指令是互斥的,其中一个符合了另外的就不会显示

刀钝刃乏:

length 是js data里面定义的,不是10 4 3

brave:

你的 length 值是多少

-EOF-

AI助手支持GPT4.0