1. 程式人生 > >1.4 Vue v-if,v-show與v-for指令

1.4 Vue v-if,v-show與v-for指令

v-if,v-show與v-for

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>v-if,v-show與v-for指令</title>
    <!--1 引入Vue庫-->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
    <div id="app"
> <!--根據慕課網DellLee老師講解的vue2.5入門課程筆記,視訊地址: https://www.imooc.com/learn/980--> <!--1 v-if 當表示式為false,則刪除,為true,則建立--> <div v-if="show">hello world</div> <button @click="handleClick">toggle</button> <!--2 v-show 當表示式為false,則隱藏,為true,則顯示
--> <div v-show="show1">hello world</div> <button @click="handleClick1">toggle</button> <ul> <!--3 v-for 迴圈集合--> <li v-for="item of list" :key="item">{{item}}</li> </ul> </div> <
script> var app = new Vue({ el: "#app", data: { show: true, show1: true, list:[1,2,3] }, methods: { handleClick: function () { this.show = !this.show; }, handleClick1: function () { this.show1 = !this.show1; } } }); </script> </body> </html>