官术网_书友最值得收藏!

  • Vue.js 2.x by Example
  • Mike Street
  • 176字
  • 2021-07-02 20:00:26

v-else

v-else allows you to render an alternative element based on the opposite of the v-if statement. If that results in true, the first element will be displayed; otherwise, the element containing v-else will. 

The element with v-else needs to directly follow the one containing v-if; otherwise, your application will throw an error.

v-else has no value and is placed within the element tag.

      <p id="app">
<p v-if="isVisible">
Now you see me
</p>
<p v-else>
Now you don't
</p>
</p>

Adding the preceding HTML to your app space will only show one of the <p> elements – toggling the value in your console as we did earlier will reveal the other container. You can also use v-else-if should you wish to chain your conditions. An example of v-else-if is as follows:

      <p id="app">
<p v-if="isVisible">
Now you see me
</p>
<p v-else-if="otherVisible">
You might see me
</p>
<p v-else>
Now you don't
</p>
</p>

You might see me will be displayed if the isVisible variable equates to false, but the otherVisible variable equates to true.

v-else should be used sparingly as can be ambiguous and might lead to false positive situation.

主站蜘蛛池模板: 苍山县| 东阳市| 曲阳县| 沅江市| 冷水江市| 九龙县| 蒲江县| 卢氏县| 临泉县| 方城县| 读书| 汶川县| 宣汉县| 山东省| 启东市| 沙田区| 礼泉县| 海兴县| 盐津县| 土默特右旗| 临猗县| 大英县| 宁海县| 聂拉木县| 莱阳市| 麻栗坡县| 奉新县| 昌都县| 东辽县| 浦城县| 黄梅县| 中卫市| 会宁县| 肇州县| 海安县| 甘南县| 永顺县| 宜春市| 浮梁县| 邯郸市| 锡林郭勒盟|