欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用vue制作滑動標(biāo)簽

 更新時間:2019年09月21日 11:19:31   作者:夏日米米茶  
這篇文章主要為大家詳細(xì)介紹了使用vue制作滑動標(biāo)簽,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue制作滑動標(biāo)簽的具體代碼,供大家參考,具體內(nèi)容如下

第一步:寫出HTML結(jié)構(gòu)

先寫一個你需要展示的靜態(tài)效果,寫好后再改為VUE動態(tài)生成,代碼如下:

<div id="app1" class="wrap">
 <ul class="tabs">
 <li class="active"><a href="javascript:" >標(biāo)簽1</a></li>
 <li><a href="javascript:" >標(biāo)簽2</a></li>
 <li><a href="javascript:" >標(biāo)簽3</a></li>
 </ul>
 <div class="tabs-con">
 <p>內(nèi)容1</p>
 </div>
 <div class="tabs-con">
 <p>內(nèi)容2</p>
 </div>
 <div class="tabs-con">
 <p>內(nèi)容3</p>
 </div>
</div>

第二步:寫出css樣式

為你的結(jié)構(gòu)寫一個樣式,代碼如下:

<style type="text/css">
 * {
 margin: 0;
 padding: 0;
 border-style: none;
 }
 ul,ol {
 list-style: none;
 }
 a {
 text-decoration: none;
 color: #777;
 }
 body {
 font: normal 14px/1.6 Helvetica,"Microsoft YaHei";
 color: #777;
 background-color: #f5f5f5;
 }
 .wrap {
 width: 600px;
 margin: 20px auto 0;
 }
 .tabs {
 overflow: auto;
 }
 .tabs li {
 float: left;
 }
 .tabs li a {
 display: block;
 padding: 10px 15px;
 color: #bbb;
 }
 .tabs li.active {
 background-color: #fff;
 }
 .tabs li.active a {
 color: #333;
 }
 .tabs-con {
 padding: 15px;
 background-color: #fff;
 }
</style>

第三步:寫出js代碼

這一步是關(guān)鍵,要用到vue的內(nèi)容了

var app1 = new Vue ({
 el: '#app1',
 data: {
 //標(biāo)簽列表的數(shù)據(jù),是數(shù)組,數(shù)組項(xiàng)是對象格式
 tabs: [
  {name:'標(biāo)簽1'},
  {name:'標(biāo)簽2'},
  {name:'標(biāo)簽3'}
 ],
 num: 0
 },
 //方法,建立自定義函數(shù),對應(yīng)點(diǎn)擊時間onclick
 methods: {
 tabsSwitch(index) {
  //用到的變量要加上this,表示使用上面構(gòu)造函數(shù)app1的對象num
  this.num = index;
 }
 }
})

第四步:更改上邊的html結(jié)構(gòu)

<div id="app1" class="wrap">
 <ul class="tabs">
 <li v-for="(tab,index) in tabs" :class="{active:num===index}" @click="tabsSwitch(index)"><a href="javascript:">{{tab.name}}</a></li>
 </ul>
 <div class="tabs-con" v-show="num===0">
 <p>內(nèi)容1</p>
 </div>
 <div class="tabs-con" v-show="num===1">
 <p>內(nèi)容2</p>
 </div>
 <div class="tabs-con" v-show="num===2">
 <p>內(nèi)容3</p>
 </div>
</div>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論