這里不跟大家再去把Vue文檔上的一些指令用法或者基礎(chǔ)知識(shí)再?gòu)?fù)述一遍,既然是從入門(mén)到實(shí)戰(zhàn),我直接將平時(shí)項(xiàng)目中需要實(shí)現(xiàn)的一些效果拆分成模塊。你們遇到了相關(guān)的指令或者不知道怎么用的方法自己對(duì)著文檔去查,再回過(guò)頭來(lái)看我的實(shí)現(xiàn)代碼。記住,通讀Vue文檔真的很重要,很重要!
創(chuàng)新互聯(lián)是一家專業(yè)的成都網(wǎng)站建設(shè)公司,我們專注成都網(wǎng)站制作、成都網(wǎng)站建設(shè)、網(wǎng)絡(luò)營(yíng)銷、企業(yè)網(wǎng)站建設(shè),買(mǎi)鏈接,一元廣告為企業(yè)客戶提供一站式建站解決方案,能帶給客戶新的互聯(lián)網(wǎng)理念。從網(wǎng)站結(jié)構(gòu)的規(guī)劃UI設(shè)計(jì)到用戶體驗(yàn)提高,創(chuàng)新互聯(lián)力求做到盡善盡美。
這里的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">歡迎來(lái)到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> 第一代選項(xiàng)卡的實(shí)現(xiàn)就先這樣子,后面再改進(jìn)。上面是代碼,下面是效果圖!Vue我也只是剛剛學(xué)入門(mén)吧,做了幾個(gè)項(xiàng)目了,有什么問(wèn)題我們可以一起探討,一起進(jìn)步,歡迎私信我!

Vue實(shí)現(xiàn)選項(xiàng)卡切換,具體代碼如下所示:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>選項(xiàng)卡</title>
<script src="../js/vue.js"></script>
<style>
li{
list-style: none;
float: left;
margin-right: 20px;
}
</style>
</head>
<body>
<div class="app">
<ul>
<li v-for="(item,index) in list" @click="tab(index)">{{item.tab}}
<div v-show="item.show">
{{item.title}}
</div>
</li>
</ul>
</div>
<script>
let obj=[
{"tab":"選項(xiàng)一","show":true,"title":"1111"},
{"tab":"選項(xiàng)二","show":false,"title":"2222"},
{"tab":"選項(xiàng)三","show":false,"title":"3333"}
];
var vm=new Vue({
el:".app",
data:{
list:obj
},
methods:{
tab:function(index){
for(var i=0;i<this.list.length;i++){
this.list[i].show=false;
if(i==index){
this.list[index].show=true;
}
}
}
}
})
</script>
</body>
</html>總結(jié)
以上所述是小編給大家介紹的vue實(shí)現(xiàn)選項(xiàng)卡及選項(xiàng)卡切換效果,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)創(chuàng)新互聯(lián)網(wǎng)站的支持!
新聞名稱:vue實(shí)現(xiàn)選項(xiàng)卡及選項(xiàng)卡切換效果
路徑分享:http://www.chinadenli.net/article44/gghsee.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗(yàn)、品牌網(wǎng)站制作、靜態(tài)網(wǎng)站、網(wǎng)站設(shè)計(jì)、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)