国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

vue頭部導(dǎo)航動(dòng)態(tài)點(diǎn)擊處理方法

2019-11-19 12:35:38
字體:
供稿:網(wǎng)友

1:DATA中兩個(gè)變量,

data: {       nav:['頭條1','頭條2'],       ins:0,//記錄當(dāng)前點(diǎn)擊的INDEX      },

2:              

 <div v-for="(item,index) in nav" :class="index == ins ? 'swiper-slide swiper_active' : 'swiper-slide' " @click="topClick(index)">{{item}}</div>

3:mothods:

topClick:function(i){        var t=this;        t.ins=i;      },

ps:下面看下vue實(shí)現(xiàn)動(dòng)態(tài)頭部

h5項(xiàng)目中,經(jīng)常用到的頭部是樣式是一致的,只是左右按鈕和中間標(biāo)題會(huì)不一致。

vue主打組件化,為了減少代碼冗余,可以將頭部提取成一個(gè)單獨(dú)的組件。接下來考慮是否需要左右按鈕,是否固定在頁面上不動(dòng),中間標(biāo)題是否為動(dòng)態(tài)。

先寫一個(gè)簡(jiǎn)單的頭部,position設(shè)置成變量customFixed。左右按鈕通過<slot>來控制。中間標(biāo)題設(shè)置成變量customTitle通過父子組件傳值過來。

設(shè)置好樣式以后給customFixed和customTitle默認(rèn)值和類型。

<template>  <div id="header" :style="{'position' : customFixed ? 'fixed' : 'absolute'}">   <slot name="left"></slot>   {{customTitle}}   <slot name="right"></slot>  </div></template><script>  export default {   name: "my-header",   props:{    customTitle : {      type : String,      default : '標(biāo)題'     },    customFixed: {      type: Boolean,      default: false    }   }  }</script><style scoped>#header{ width: 100%;height: 40px;background: #666;color: white;text-align: center;line-height: 40px; position: absolute;left:0;top: 0;z-index: 10;} #header button {height: 100%;padding: 0 50px;} #header button:nth-of-type(1){float: left} #header button:nth-of-type(2){float: right}</style>在用到頭部的地方:<template> <div id="app">  <my-header custom-title="通訊錄" custom-fixed>   <button @click="backBtn" slot="left">返回</button>   <button @click="homeBtn" slot="right">主頁</button>  </my-header> </div></template> 

總結(jié)

以上所述是小編給大家介紹的vue頭部導(dǎo)航動(dòng)態(tài)點(diǎn)擊處理方法,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)武林網(wǎng)網(wǎng)站的支持!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 博客| 怀仁县| 澄城县| 筠连县| 陵水| 磴口县| 长岛县| 珲春市| 清原| 隆德县| 株洲县| 南昌市| 新津县| 德保县| 尼勒克县| 永济市| 襄城县| 宁陕县| 咸阳市| 武鸣县| 新化县| 镇雄县| 贺州市| 新巴尔虎右旗| 湖口县| 合肥市| 扎鲁特旗| 玉林市| 陕西省| 榆社县| 柘城县| 都安| 元氏县| 遂平县| 昂仁县| 汤阴县| 长治市| 曲周县| 周至县| 长治县| 东阳市|