<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> ul li { list-style: none; display: inline-block; border: 1px solid dodgerblue; height: 30px; line-height: 30px; width: 120px; text-align: center; } </style> <script src="vue.js"></script> </head> <body> <div id="box"> <ul> <li v-on:click="qh(true)"> <span >二維碼登陸</span> </li> <li v-on:click="qh(false)"> <span >郵箱登陸</span> </li> </ul> <div style="margin-left:80px" v-if="temp"> <img src="getUrlQrcode.jpg" alt=""> </div> <div style="margin-left:80px" v-if="!temp"> <form action="https://mail.163.com/" method="post"> <p><input type="email"></p> <p><input type="password"></p> <p><input type="submit" value="登陸"></p> </form> </div> </div> <script> new Vue({ el: '#box', data: { temp:true }, methods:{ qh:function (t) { console.log(t); this.temp=t } } }) </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> ul li { list-style: none; display: inline-block; border: 1px solid dodgerblue; height: 30px; line-height: 30px; width: 120px; text-align: center; } </style> <!-- 引用vue.js文件 --> <script src="vue.js"></script> </head> <div id="app"> <ul> <!--- 給li標籤綁定click時間,點擊該li標籤將索引傳給函數從新賦值給num---> <li v-for="(index,item) in tabs" :class="{active:index == num}" @click="tab(index)"> {{item}}{{index}} </li> </ul> <div class="tabCon"> <!--- 循環遍歷tabContents數組中的元素,v-show綁定事件,當循環的索引等於num中的值,顯示該itemCon值 ---> <div v-for='(index,itemCon) in tabContents' v-show="index == num"> {{itemCon}}{{index}} </div> </div> </div> <!--這裏是js代碼--> <script type="text/javascript"> var vm = new Vue({ el: '#app', data: { tabs: ["標題一", "標題二","標題三"], tabContents: ["內容一", "內容二","內容三"], num: '' }, methods: { tab:function (index) { this.num = index; } } }); </script>