Vue學習之vue中的v-if,v-show,v-for
阿新 • • 發佈:2019-01-06
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>vue</title> <script src="vue.js"></script> </head> <body> <!-- vue中的v-if,v-show,v-for v-if: v-show:display:none/block v-for: --> <div id="root"> <div v-if="show">hello dog</div> <button @click="handleClick">toggle</button> <ul> <li v-for="(item, index) of list" :key="index">{{item}}</li> </ul> </div> <script> new Vue({ el:"#root", data:{ show: true, list: [1,2,3] }, methods: { handleClick: function() { this.show = !this.show } } }) </script> </body> </html>