這里不跟大家再去把Vue文檔上的一些指令用法或者基礎(chǔ)知識(shí)再復(fù)述一遍,既然是從入門到實(shí)戰(zhàn),我直接將平時(shí)項(xiàng)目中需要實(shí)現(xiàn)的一些效果拆分成模塊。你們遇到了相關(guān)的指令或者不知道怎么用的方法自己對著文檔去查,再回過頭來看我的實(shí)現(xiàn)代碼。記住,通讀Vue文檔真的很重要,很重要!
這里的Vue以單文件的形式引入,另外代碼在實(shí)現(xiàn)上會(huì)一步步的進(jìn)行優(yōu)化,客官不要著急!
下面是一個(gè)樣式稍微丑陋,但功能OK的選項(xiàng)卡。
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=no,width=device-width"> <meta name="apple-mobile-web-app-title" content="Vue選項(xiàng)卡"> <title>Vue實(shí)現(xiàn)選項(xiàng)卡</title> <script type="text/javascript" src="../js/vue.js"></script> </head> <style> * { padding: 0; margin: 0; } .box { width: 800px; height: 200px; margin: 0 auto; border: 1px solid #000; } .tabs li { float: left; margin-right: 8px; list-style: none; } .tabs .tab-link { display: block; width: 250px; height: 49px; text-align: center; line-height: 49px; background-color: #5597B4; color: #fff; text-decoration: none; } .tabs .tab-link.active { height: 47px; border-bottom: 2px solid #E35885; transition: .3s; } .cards { float: left; } .cards .tab-card { display: none; } .clearfix:after { content: ""; display: block; height: 0; clear: both; } .clearfix { zoom: 1; } </style> <body> <div id="app" class="box"> <ul class="tabs clearfix"> <li v-for="(tab,index) in tabsName"> <a href="#" rel="external nofollow" class="tab-link" @click="tabsSwitch(index)" v-bind:class="{active:tab.isActive}">{{tab.name}}</a> </li> </ul> <div class="cards"> <div class="tab-card" >這里是HTML教程</div> <div class="tab-card">歡迎來到CSS模塊</div> <div class="tab-card">嗨,這里是Vue</div> </div> </div> </body> <script> var app = new Vue({ el: "#app", data: { tabsName: [{ name: "HTML", isActive: true }, { name: "CSS", isActive: false }, { name: "Vue", isActive: false }], active: false }, methods: { tabsSwitch: function(tabIndex) { var tabCardCollection = document.querySelectorAll(".tab-card"), len = tabCardCollection.length; for(var i = 0; i < len; i++) { tabCardCollection[i].style.display = "none"; this.tabsName[i].isActive = false; } this.tabsName[tabIndex].isActive = true; tabCardCollection[tabIndex].style.display = "block"; } } }) </script> </html>
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
網(wǎng)站欄目:vue實(shí)現(xiàn)選項(xiàng)卡及選項(xiàng)卡切換效果-創(chuàng)新互聯(lián)
新聞來源:http://www.rwnh.cn/article30/ddddso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、網(wǎng)站設(shè)計(jì)公司、企業(yè)建站、定制網(wǎng)站、域名注冊、網(wǎng)站維護(hù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容