Blogger Information
Blog 50
fans 0
comment 0
visits 31450
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
实例演示列表渲染与条件渲染指令
手机用户1580651468
Original
732 people have browsed it

实例演示列表渲染与条件渲染指令

一、实例演示列表渲染

一)快速输出列表代码片段

  1. <!-- v-for指令快速循环输出列表 -->
  2. <ul>
  3. <li v-for="city of cities">{{city}}</li>
  4. </ul>
  5. <hr />
  6. <ul>
  7. <li v-for="(item,key) of user" :key="key">{{key}}:{{item}}</li>
  8. </ul>
  9. <script>
  10. const app = Vue.createApp({
  11. data() {
  12. return {
  13. cities: ["合肥", "上海", "南京"],
  14. user: {
  15. name: "朱老师",
  16. email: "65535424@qq.com",
  17. },
  18. };
  19. },
  20. });
  21. const vm = app.mount(".app");
  22. </script>

二)实现的效果图

二、实例演示列条件渲染指令

一)v-if:条件渲染指令代码

  1. <div class="app">
  2. <!-- v-if:条件渲染指令 -->
  3. <p v-if="flag">{{message}}</p>
  4. <button v-text="flag ? '影藏':'显示'"></button>
  5. <!-- if-else,if else if -->
  6. <p v-if="point>=1000&&point<2000">{{grade[0]}}</p>
  7. </div>
  8. <script>
  9. Vue.createApp({
  10. data() {
  11. return {
  12. message: "前端快结束了",
  13. flag: true,
  14. // 会员plus级别
  15. grade: ["纸片会员", "木头会员", "铁皮会员", "金牌会员", "非会员"],
  16. point: 1500,
  17. };
  18. },
  19. }).mount(".app");
  20. </script>

一)v-if:条件渲染实现效果

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:完成的不错, 继续加油
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments